我试图在发布表单时发布一组对象,但我总是在控制器中得到一个空列表
JavaScript
function defineuser(userList) {
var user = null;
var userAppModuleItemList = new Array();
for (var i = 0; i < userList.length; i++){
values = userList[i].split(",");
user = {
ID: values[0],
Name: values[1],
LastName: values[2]
};
userAppModuleItemList.push(user );
}
$("#userList").val(userAppModuleItemList);
};
看法
<%using (Html.BeginForm("UpdateUser", "User", FormMethod.Post, new { id = "userForm" }))
{%>
<%=Html.Hidden("userList")%>
...
<%}%>
控制器
[HttpPost]
public JsonResult UpdateUser(List<UserDTO> userList)
{
// The userList is null
}
用户类定义
public class UserDTO
{
public int ID { get; set; }
public string Name { get; set;}
public string LastName { get; set; }
}
谢谢你的帮助