0
我有這個模型ASP.NET MVC - 無法綁定表單值列出<Model>
public class ItemClassification
{
public int ItemID {get; set;}
public string ItemName {get; set;}
}
,我有這種形式
<form method="POST" action="/Home/UpdateItemClassifications">
<table>
<tr>
<th>Item ID</th>
<th>Item Name</th>
</tr>
<tr>
<td>
<input name="ItemClassification[0].ItemID" value="1"/>
</td>
<td>
<input name="ItemClassification[0].ItemName" value="Item One"/>
</td>
</tr>
<tr>
<td>
<input name="ItemClassification[1].ItemID" value="2"/>
</td>
<td>
<input name="ItemClassification[1].ItemName" value="Item Two"/>
</td>
</tr>
<tr>
<td>
<input name="ItemClassification[2].ItemID" value="3"/>
</td>
<td>
<input name="ItemClassification[2].ItemName" value="Item Three"/>
</td>
</tr>
</table>
</form>
而且我想要綁定這些值來這控制器動作循環它們並在數據庫中更新它們。
[HttpPost]
public ActionResult UpdateItemClassifications(List<ItemClassification> UpdatedClassifications)
{
//save logic here..
}
無論出於何種原因,我沒有獲取綁定到ItemClassification模型的發佈表單值。任何幫助或方向將不勝感激。我試圖用僅有一組值的方式發佈此表單,並從控制器中刪除了「列表<>」,並正確映射了這些值。
如果它們是按順序排列,請嘗試刪除「ItemClassification」並放置[0] .ItemID – Sunny 2013-03-23 19:05:39
如果它們沒有按順序排列,則需要在每個項目前都有隱藏值攜帶索引,請檢查http:// haacked。 COM /存檔/ 2008/10/23 /模型綁定到一個-list.aspx – Sunny 2013-03-23 19:08:39