MVC4 애플리케이션에는 관리자 파트가 있습니다. 이 관리자보기에서는 등록되지 않은 (아직) 승인 된 사용자를 모두 볼 수 있습니다. 이보기는 ienumerable의 편집기이기도합니다. 를 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<T>
걱정하지 않는 경우
IEist를 사용할 때, IEnumerable을 사용할 때 컨트롤러에 양식을 제출할 때 Model이 null이되기 때문에 걱정하지 않습니다. –
devqon
@ user3153169, 수정 된 답변 참조 – Zabavsky