开发者

Passing JSON to a PageMethod that expects a List<T> parameter

I have an ASP.NET PageMethod with the following signature:

<WebMethod()> _
Public Shared Function SaveCodes(ByVal codes As List(Of Code)) As String

I am trying to pass a JSON object to the PageMethod from the client side, but I get an error that the type String cannot be converted to type of List<Code>.

Here is the json that I'm building on the client and sending to the method:

{

'codes' : {

{ "companyID": "00000000-0000-0000-0000-000000000000", "customerType":"1", "code":"11 " },

{ "companyID": "00000000-0000-0000-0000-000000000000", "customerType":"1", "code":"21 " }

}

}

Here is my PageMethod 开发者_StackOverflowcall, (objects is the json string above):

PageMethods.SaveCodes(objects, successFn, errorFn);

I have been able to pass in simple data types and a single instance of the Code class, but I can't seem to find the magic to pass a List to the server method. Can anyone show me what I'm doing wrong?


I was able to figure it out. The correct notation is listed below. The main piece that was missing was the __type property for each object. I had to dig around in a List that was returned from a PageMethod to find that.

{"codes":
[  
{"CompanyID":"00000000-0000-0000-0000-000000000000","Code":"11    ","CustomerType":"1","__type":"Code"},
{"CompanyID":"00000000-0000-0000-0000-000000000000","Code":"21    ","CustomerType":"1","__type":"Code"}
]
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜