Error Calling C# Function From Javascript

Apr 18, 2012 at 8:00 PM

Hi all,

I'm attempting to use C# with Javascript .NET to interact with a web service which passes back a string with two substrings: an ID and a Javascript function to execute. For example, the string could look like:




I'd like to arrange it so that this Javascript dispatch will call a C# dispatch and handle things appropriately. What's happening now, though, is that the C# dispatch is being called with the appropriate first parameter (the ID) but the second parameter (the function) is coming across as:




I want it to come across as:


I'm setting things up with:

_js.Run("function dispatch(v, w) { NS.dispatch(v, w); }");

And my C# dispatch signature is:

public void dispatch(string poid, string script){}
Any ideas how I can force the string to come through to the C# dispatch as an actual string and not as the Generic.Dictionary? It seems like it's trying to figure out what type to pass it as rather than just passing it as a string. Thanks for the help.

Apr 18, 2012 at 11:22 PM

The second parameter to NS.dispatch is an anonymous function, not a string.  Javascript.NET is treating it as a JavaScript object, which is why you see the dictionary.  If the original input was something like the below then you would get what you want.