0

我试图在发布表单时发布一组对象,但我总是在控制器中得到一个空列表

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; } 
}

谢谢你的帮助

4

1 回答 1

0

尝试traditional : true发布数组对象

$.ajax({ 
      type: "POST",
      url: "<%= Url.Action("MyAction","Controller")%>",
      datatype: "json",
      traditional: true,
      data: { userList : arrayOfValues }              
 });
于 2013-11-07T03:55:21.390 回答