The recent use of the post-pass array parameter in ASP. NET MVC is documented for reference.
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:
Public class UserInfo { publicintgetset;} Public string Get Set ; } }
Second, backstage code
The background action code is as follows:
[HttpPost] public actionresult testpost (list<string > A, userinfo[] b) { varnewtrue" you are 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() { vardata = {}; data["A[0]" [] = "Test"; data["a[1]" = "Just"; data[[B[0]. UserId "] = 1; data[[B[0]. UserName "] =" Zhang "; data[[B[1]. UserName "] =" Sir Huang "; $.post (' @Url. Action ("Testpost") ', data,function(res) {alert (' Result: ' + res. Issuccess + ', Error: ' +Res. ERRMSG); }); }); }); </script>Iv. SummaryThe 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; ....
Example of passing array parameters as post in ASP.