이것은 내보기 코드입니다.asp.net에서 모델의 페이지 제목을 설정하는 방법은 무엇입니까?
@model IEnumerable<TestApplication.Models.ApplicationUser>
@{
Layout = null;
ViewBag.Title = //what goes here? Model.FirstName?
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
</head>
<body>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.FirstName)
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
@Html.ActionLink("Details", "Details", new { id=item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.Id })
</td>
</tr>
}
</table>
</body>
</html>
ViewBag의 제목을 모델에있는 이름으로 변경하고 싶습니다. ViewBag.Title = Model.FirstName
과 같은 것을 기대하고 있습니다. 하지만 이렇게하면 오류가 발생합니다. 구문은 무엇입니까?
ViewBag.Title = Model.First().FirstName;
이 오류가 사라지는해야하지만,이는 다음과 같습니다
무슨 오류가 발생합니까? –
모델은'IEnumerable'이고'IEnumerable'는 속성이 없습니다. 하지만 왜 'ApplicationUser''FirstName' 값 중 하나를''의'' 태그에 할당하려고합니까? –
방금 테스트 중이었습니다. 그것은 무작위적인 것입니다. –