2009-08-31 22 views
0

我有更新的實體的列表,可以像做這些這是可能得到與asp.net的MVC後動作

<%using (Html.BeginForm()) 
    { 
%> 

<% foreach (var entity in Model) 
    { 
%> 
<p> 
    <%= Html.TextBox("Entity.Name", entity.Name) %> 
</p> 
<% } %> 
    <input type="submit" value="Update" /> 
<% } %> 

,然後在一個參數列表行動接收實體列表?或一個名單的列表... 我不想爲每個實體創建一個自己的表單,我想更新所有的實體toghether。 我必須做這些?

由於提前,

阿爾弗雷

+0

儘量不要在數據庫中爲您的列使用名稱「name」,也可以使用它的實體,例如「Categoryname,Productname」等。否則,隨着應用程序的增長,它會變得非常混亂 – 2009-08-31 11:03:43

回答

1
<%= Html.TextBox("name", entity.Name) %> 

public ActionResult foo(string[] name) 

<%= Html.TextBox("Entity["+index+"].Name", entity.Name) %> 

//will create list of entities from form values 
public ActionResult foo(IList<Entity> entity) 

在Asp.Net MVC術語中的過程稱爲模型綁定。

This文章可能值得一試。和關於綁定列表的another one

相關問題