, . , .
-, , null , , . :
<input id="item_CanWrite" name="item.CanWrite" type="checkbox" value="true" />
<input name="item.CanWrite" type="hidden" value="false" />
, name - item.CanWrite. , , , . MVC POSTed, User.
, Html.DisplayFor, MVC User , User . . :
@for (int i = 0; i < Model.Count(); i++)
{
<tr>
<td>
<input type="checkbox" name="id" value="@Model[i].ID" checked=checked/>
</td>
<td>
@Html.DisplayFor(m => m[i].ID)
</td>
<td>
@Html.DisplayFor(m => m[i].Name)
</td>
<td>
@Html.DisplayFor(m => m[i].Email)
</td>
<td>
@Html.CheckBoxFor(m => m[i].CanWrite)
</td>
<td>
@Html.CheckBoxFor(m => m[i].IsAdmin)
</td>
</tr>
}
, HTML, , :
<input checked="checked" data-val="true" data-val-required="The CanWrite field is required." name="[0].CanWrite" type="checkbox" value="true" />
<input name="[0].CanWrite" type="hidden" value="false" />
<input checked="checked" data-val="true" data-val-required="The CanWrite field is required." name="[1].CanWrite" type="checkbox" value="true" />
<input name="[1].CanWrite" type="hidden" value="false" />
, User . , :
[HttpPost]
public ActionResult Index(IEnumerable<User> model)
{
return View(model);
}
, , , . DisplayTemplates :
DisplayTemplates (, Home\Index.cshtml, Home\DisplayTemplates).- , (..
User.cshtml). - .
( , User):
@model User
<tr>
<td>
<input type="checkbox" name="id" value="@Model.ID" checked=checked/>
</td>
<td>
@Html.DisplayFor(m => m.ID)
</td>
<td>
@Html.DisplayFor(m => m.Name)
</td>
<td>
@Html.DisplayFor(m => m.Email)
</td>
<td>
@Html.CheckBoxFor(m => m.CanWrite)
</td>
<td>
@Html.CheckBoxFor(m => m.IsAdmin)
</td>
</tr>
, , :
@using (Html.BeginForm())
{
<table>
@Html.DisplayForModel()
</table>
<input type="submit" value="Submit" />
}
, . .