开发者

Working with identifiers as arrays and sending to MVC controller

I have some identifiers on my page. Named id[0], id[1] all the way to id[20] and s开发者_Go百科ometimes more. I need to send these to an MVC controller and I would like to package them up as one object and unpack at the controller. Can someone tell me if this is possible, my knowledge of javascript is just basic so I'd really appreciate advice on which way to go. For example can I use JSON or serialize. btw I'm using jQuery.

Gordon


You can send your data in JSON.

See > ASP.NET MVC How to pass JSON object from View to Controller as Parameter


If you already have the id array (id[0], id1 , ... id[20]) you can convert it to JSON string with respect of JSON.stringify(id) where JSON.stringify function defined in the json2.js.

On the server side you can use for example Deserialize method of the JavaScriptSerializer to convert the data to List<T> where T is type of id[i] (for example string).

How to send data with respect of jQuery.ajax you already know from another answer.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜