May 20, 2014, 11:53 AM
DirectMethod - how to pass an array parameter
Hi guys,
Let's say I want to call a DirectMethod on my JS client, passing an array of strings as one of the parameters. Something like:
Thanks in advance!
Let's say I want to call a DirectMethod on my JS client, passing an array of strings as one of the parameters. Something like:
App.direct.MyMethod(["arrayValue1","arrayValue2"]);
I assumed a corresponding server-side method that receives a string array would would work and I'd get my array. However, what I actually get an array with only one element - the client-side array as a string. [DirectMethod]
public ActionResult MyMethod(string[] arrayParameter) {
// By inspecting arrayParameter, we get [ "[\"arrayValue1\",\"arrayValue2\"]" ]
...
}
I found a workaround, which involves receiving the array as a string and deserializing it:[DirectMethod]
public ActionResult MyMethod(string arrayParameterAsString) {
var myArray = JsonConvert.DeserializeObject<string[]>(arrayParameterAsString);
// Do stuff with parameters
...
}
But my gut feeling tells me there's a simpler way to do this. Is there some way to tell Ext.NET that I want a parameter to be treated as an array on my server method?Thanks in advance!