問題是我需要在School視圖中「調用」PersonName字段,但視圖School中的模型是@model IList<Project.Presentation.Models.SchoolViewModel>
,並且字段PersonName在型號爲@model IList<Project.Presentation.Models.PersonViewModel>
。 所以,我想我必須在同一視圖中使用兩個模型,但我不知道該怎麼做。我不知道我是否只能使用一個代碼行來「調用」我需要的字段,或者如果我必須執行某些操作。ASP.NET MVC-在同一視圖中使用兩個模型
這裏是在視圖中學校代碼:
@model IList<Project.Presentation.Models.SchoolViewModel>
@{
ViewBag.Title = "Start view";
}@
{
<div class="row">
<div class="col-md-6 ">
<h2>
Details of the person @Html.DisplayFor(Project.Presentation.Models.PersonViewModel.PersonName)
</h2>
</div>
</div>
}
我與@Html.DisplayFor(Project.Presentation.Models.PersonViewModel.PersonName)
努力,但顯然它不工作。
創建包含屬性您需要的視圖模型 –