Asp.net mvc 如何将列表绑定到控制器

Asp.net mvc 如何将列表绑定到控制器,asp.net-mvc,binding,Asp.net Mvc,Binding,如何将列表绑定到控制器 我的控制器、HTTPGET和HTTPPOST中的代码: public ActionResult Client(string id) { List<Customer> Contacts = WebService.GetContactsOfClient(id); return View(Contacts); } [HttpPost] public ActionR

如何将列表绑定到控制器

我的控制器、HTTPGET和HTTPPOST中的代码:

 public ActionResult Client(string id)
    {               
        List<Customer> Contacts = WebService.GetContactsOfClient(id);   
        return View(Contacts);
    }

    [HttpPost]
    public ActionResult Client(List<Customer> custs)
    {          
        // custs = null!!! Why??
        return View();

    }
在我看来:

 <% using (Html.BeginForm("Client", "Formulaire", FormMethod.Post, new { id = "form" })) { %>
        <% foreach (var item in Model) { %>
            <%:item.MiseAjour %><br />
        <% } %>

        <input type="submit" />
<% } %>

谢谢大家……

这概述了您正在努力实现的目标


如果您有特定的问题,请发布这些问题。

如果您希望模型绑定器将您的模型重新组合到文章中,您的视图不会呈现所需的任何html输入元素。请参见显示绑定到集合和向后发布的内容。另请查看此帖子。

如果您想在帖子操作中获得一些值,您需要发布它们,这是使用输入字段实现的:

<% using (Html.BeginForm() { %>
    <%= Html.EditorForModel() %>
    <input type="submit" value="OK" />
<% } %>
我的解决方案:

<legend>Contacts</legend>
      <% for (int i = 0; i < Model.Contacts.Count; i++) { %>

            <%: Html.EditorFor(model => model.Contacts[i],"Contact") %>

        <% } %>
有了这个,我将我的列表绑定到控制器


谢谢大家

如果要将列表发送到您的视图,为什么要在BeginForm帮助程序中发送id?我进行了编辑以删除asp.net标记,因为这与asp.net无关。在这种情况下,asp.net和asp.net-mvc是完全不同的different@Ikaso:id是html属性的可能重复项-之前已多次回答,请尝试搜索绑定到列表的模型,绑定到ienumerable的模型