Model binding to a list

Phil Haack Article: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/




 

  •  



 

  •  



 

  •  


ListBinding/Index.cshtml
@using (Html.BeginForm())
{
<table class="tt">
@for (var j = 0; j < Model.Dinners.Count(); j++)
{
var i = j;
<tr>
<td>
@Html.HiddenFor(o => o.Dinners[i].Id)
@Html.Awe().TextBoxFor(o => o.Dinners[i].Name).Value(Model.Dinners[i].Name)
@Html.ValidationMessageFor(o => o.Dinners[i].Name)
<br />
</td>
<td>
@Html.Awe().DatePickerFor(o => o.Dinners[i].Date).Value(Model.Dinners[i].Date).ClearButton()<br />
@Html.ValidationMessageFor(o => o.Dinners[i].Date)
</td>
<td>
@Html.Awe().LookupFor(o => o.Dinners[i].Chef).Value(Model.Dinners[i].Chef).ClearButton()<br />
@Html.ValidationMessageFor(o => o.Dinners[i].Chef)
</td>
<td>
@Html.Awe().MultiLookupFor(o => o.Dinners[i].Meals).Value(Model.Dinners[i].Meals).ClearButton()<br />
@Html.ValidationMessageFor(o => o.Dinners[i].Meals)
</td>
</tr>

}
</table>
<br/>
<input type="submit" value="submit" class="awe-btn mbtn"/>
}