2010-07-12 65 views

回答

0

視圖模型中可以傳回一個列表使用Html.hidden爲列表的每個元素。

只要您在視圖中使用for循環處理列表元素(foreach不起作用),視圖模型中的列表屬性將重新構建。例如:

@for (var i = 0; i < Model.Nutrients.Count(); i++) 
{ 
    // This ensures that the list of nutrients is passed in the view model back to the controller 
    @Html.HiddenFor(m => m.Nutrients[i].Name); 
    @Html.HiddenFor(m => m.Nutrients[i].Id); 
} 
相關問題