I am trying to make an editor for an object in ASP.net MVC 3. It looks something like this:
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.foo)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.foo)
@Html.ValidationMessageFor(model => model.foo)
</div>
@if (Model.Items.Count > 0)
{
<table>
@foreach (var ii in Model.Items)
{ @Html.EditorFor(item => ii) }
</table>
}
In this example, Items is a list of another kind of object. The problem is, when the model is posted back from being edited in the view, the data changes to Model.Items aren’t there, while the data changes to Name and foo work. How can I make it so that the data for Items binds correctly?
Model class:
Controller class:
View:
You don’t have to iterate through
Items.