Monday, March 28, 2011

Can I pass an array to a .Net Ajax PageMethod?

I am using .Net Ajax PageMethods. I was hoping I could pass a javascript array into my method but I am getting the error: "Type 'System.Array' is not supported for deserialization of an array". Here is a simplified version of what I am doing:

Client Side Code:

function AddItemsToBatch()
{
var stuff = new Array();
stuff[0] = "one thing";
stuff[1] = "some other thing";
PageMethods.AddToBatch(stuff,OnSuccess,OnFail);
}

Server Side Code:

<Web.Services.WebMethod()> Public Shared Function AddToBatch(ByVal stuff as Array) as Boolean
  Return True
End Function
From stackoverflow
  • Try using a collection like an array of strings or objects. IIRC, System.Array is abstract.

    brendan : That was it, changed to array of strings and that worked - should have realized. Thanks!

0 comments:

Post a Comment