在我的MVC4应用程序中,我有一个管理部分。在这个管理员视图中,我可以看到所有未注册的用户。这个观点也是一个可编辑的编辑器。为了有一个IEnumerable一个编辑,我已经添加的IList和环在我看来是这样的:用于MVC4模型绑定的IList
@model IList<PlusPlatform.Models.UserProfile>
@{
ViewBag.Title = "Manage";
}
<h2>@ViewBag.Title</h2>
@using (Html.BeginForm())
{
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.UserName)
</th>
<th>
@Html.DisplayNameFor(model => model.FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.DepartmentId)
</th>
<th>
@Html.DisplayNameFor(model => model.IsActivated)
</th>
</tr>
@for (var i = 0; i < Model.Count(); i++) {
<tr>
<td>
@Html.EditorFor(modelItem => Model[i].UserName)
</td>
<td>
@Html.EditorFor(modelItem => Model[i].FirstName)
</td>
<td>
@Html.EditorFor(modelItem => Model[i].LastName)
</td>
<td>
@Html.EditorFor(modelItem => Model[i].DepartmentId)
</td>
<td>
@Html.EditorFor(modelItem => Model[i].IsActivated)
</td>
</tr>
}
</table>
<input type="submit" value="Save" />
}
但现在的问题是我不能使用Html.DisplayNameFor和Html.LabelFor。我能做些什么来正确显示标签?
我关心IList,因为当我使用'IEnumerable'时,在将表单提交给控制器时,模型将为空。 –
devqon
@ user3153169,请参阅编辑的答案。 – Zabavsky