2009-05-26 34 views
1

有很多关于如何使用内置模型绑定功能自动获取项目列表的示例。但是他们都提到了ASP.net MVC的Beta版本。还有人提到,这种模式绑定已经发生了变化,但到目前为止,我还无法找到它在最终版本中如何工作的好消息。而且我很有能力解释源代码:-)在ASP.Net MVC中绑定IList最终版本

所以如果有人能解释我将如何在视图中准备一个值列表来很好地回到具体对象的IList。

感谢您的帮助

MAIK

回答

3

查看:

<% using(Html.BeginForm("Retrieve", "Home")) %> { %> 
<% var counter = 0; %> 
    <% foreach (var app in newApps) { %> 
    <tr> 
     <td><%=Html.CheckBox(String.Format("myAppList[{0}].Id", counter), app.ApplicationId) %></td> 
     <!-- ... --> 
     <td><%=Html.Input(String.Format("myAppList[{0}].SomeProperty1", counter), app.SomeProperty1) %></td> 
     <td><%=Html.Input(String.Format("myAppList[{0}].SomePropertyN", counter), app.SomePropertyN) %></td> 
     <% counter = counter + 1; %> 
    </tr> 
    <% } %> 
    <input type"submit" /> 
<% } %> 

控制器:

[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Retrieve(IList<MyAppObject> myAppList) 
+0

哎哟,这是几乎要容易。谢谢你的帮助。 – 2009-06-24 19:21:12