First, prepare the Parameter object
In this case, I'll pass two array parameters: an array of strings, a custom array of objects. The custom object userinfo is defined as follows:
Class UserInfo { setset;}}
Second, backstage code
The background action code is as follows:
[HttpPost] Public ActionResult testpost (list<string> A, userinfo[] b) { " you're wrong. " return Json (result, jsonrequestbehavior.allowget);}
Where the list or array method is the same for the front-end code.
Third, the front-end code
The front-end jquery calling code is as follows:
$(function () {$ (' #btnTest '). Click (function () {var data = {}; data["a[0]"] = "Test" ; data["a[1]" = "Just" data[" b[0]. UserName "] =" Zhang "function
Iv. Summary
The key to passing array parameters in ASP. Post is the way JSON objects are written, and here's a summary:
Define the Empty object first: var data = {};
For list<string>, list<int> and other simple types, data["a[0" "] =" DD "; data["a[1]" = "D2"; ....
For complex types, such as List<userinfo>, userinfo[],data["b[0". UserId "] = 1; ....
(forward) example of passing array parameters as post in ASP.