我无法找到解决问题的方法,我尝试了很多替代方案,但我无法解决.
我首先使用模型生成我的数据库,之后我使用Scaffolding生成视图(索引,创建,编辑,删除..).唯一的视图(索引)与模型使用IEnumerable.
索引视图是:
@model IEnumerable<CAD_CMDBv2.Models.Location>
@{
ViewBag.Title = "Location's Management";
}
<h2>All Locations</h2>
<p>
@Html.ActionLink("Create Location", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Location.site_name)
</th>
<th>
@Html.DisplayNameFor(model => model.Location.country_name)
</th>
<th>
@Html.DisplayNameFor(model => model.Location.region_name)
</th>
<th></th>
</tr>
@foreach(var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Location.site_name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Location.country_name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Location.region_name)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Location.location_id }) |
@Html.ActionLink("Details", "Details", new { id = item.Location.location_id }) |
@Html.ActionLink("Delete", "Delete", …Run Code Online (Sandbox Code Playgroud)