2009-06-23 91 views
2

我有一個場景我想使用局部視圖,但是我有問題將它傳遞給控制器​​。這是我想要做的一個基本例子。ASP.NET MVC部分視圖和表格

對象:

  • 客戶
  • 訂購

客戶上有一個IList<Order>。我想讓局部視圖允許用戶編輯信息。我可以獲取要顯示的數據,但是當表單發佈Customer對象下的列表爲空時。

我也試圖在我的部分視圖中使用單獨的窗體。當我這樣做,如果我在控制器上創建paramenters喜歡,所以我得到的數據:

public ActionResult UpdateOrders(IList<Guid> id, IList<int> quantity, IList<Guid> productId) 

但是,當我做到這一點

public ActionResult UpdateOrders(IList<Order> orders) 

列表爲空。

如果任何人有更好的建議如何實現這個讓我知道。

+0

你可以發佈HTML,我認爲這將有助於這個問題 – Hugoware 2009-06-23 16:45:14

回答

2

你如何引用視圖中的字段?我想,這應該是這樣的:

<input type="hidden" name="orders.Index" value="0" /> 
<input type="hidden" name="oders[0].ID" value="1" /> 
<input type="hidden" name="orders[0].productId" value="4" /> 
<input type="text" name="orders[0].quantity" value="6" /> 

<input type="hidden" name="orders.Index" value="1" /> 
<input type="hidden" name="orders[1].ID" value="2" /> 
<input type="hidden" name="orders[1].productId" value="2" /> 
<input type="text" name="orders[1].quantity" value="15" /> 

見菲爾哈克對binding to a list博客條目獲取更多信息。

+0

這些字段是由foreach生成的,因此它們最終以相同的id和名字結束。 – cjibo 2009-06-23 17:01:27