2010-07-12 63 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); 
} 
相关问题