在ASP.NET MVC中向服务器发送对象数组时发出问题

时间:2013-04-21 05:00:16

标签: c# asp.net-mvc asp.net-mvc-4

我正在使用ASP.NET MVC 4处理应用程序。我正在尝试将对象数组发送到控制器。我的观点包含:

<input type="hidden" id="1" name="Persons" value='[
 {"Id":1,"Name":"Abc","Description":"this is desc"},
 {"Id":2,"Name":"def","Description":"this is desc"},         
 {"Id":4,"Name":"ghi","Description":"this is desc"}]'
/>

我的控制器动作是这样的:

public ActionResult create(List<Person> Persons)
{
  //Here the Persons count is always 0, why ?
} 

当我发布我的表格时,我总是会让人数为0.有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

尝试将输入值更改为:

{Persons: [
    {"Id":1,"Name":"Abc","Description":"this is desc"},
    {"Id":2,"Name":"def","Description":"this is desc"},         
    {"Id":4,"Name":"ghi","Description":"this is desc"}
]}