Example of passing array parameters in ASP. net mvc in post mode, asp. netmvc
Recently, I used ASP. NET MVC to pass array parameters in post mode and record them for reference.
1. Prepare the parameter object
In this example, we will pass two array parameters: A String Array and a custom object array. This custom object UserInfo is defined as follows:
public class UserInfo { public int UserId { get; set; } public string UserName { get; set; } }Ii. Background code
The background Action code is as follows:
[HttpPost] public ActionResult TestPost (List <string> a, UserInfo [] B) {var result = new {IsSuccess = true, ErrMsg = "You are wrong "}; return Json (result, JsonRequestBehavior. allowGet );}
The List or array method is the same for front-end code writing.
3. Front-end code
The front-end jquery call code is as follows:
<Html> Iv. Summary
In ASP. net mvc, the key to passing array parameters in post mode is the json object writing method. Here we will summarize:
First define an empty object: var data = {};
For simple types such as List <string> and List <int>, data ["a [0]"] = "dd "; data ["a [1]"] = "d2 ";....
For complex types, such as List <UserInfo>, UserInfo [], data ["B [0]. UserId"] = 1 ;....