【发布时间】:2017-04-17 04:18:53
【问题描述】:
我正在尝试在我的项目索引视图中显示我的检查模型中的某些数据。他们目前有 M:M 关系。
这是错误
错误 CS1061 '
IEnumerable<Item>' 不包含 'Inspection' 的定义,并且没有扩展方法 'Inspection' 接受类型为 'IEnumerable<Item>' 的第一个参数(您是否缺少使用指令还是程序集引用?)
有什么建议吗?谢谢
这是项目索引
@model IEnumerable<NCSafety.Models.Item>
<table class="table">
<tr>
<th>
Hazard Picture
</th>
<th>
@Html.DisplayNameFor(model => model.Hazard.hazName)
</th>
<th>
@Html.DisplayNameFor(model => model.Inspection.ID)
</th>
<th>
@Html.DisplayNameFor(model => model.itemCorrActionDue)
</th>
<th>
@Html.DisplayNameFor(model => model.itemCorrActionCompleted)
</th>
<th>
@Html.DisplayNameFor(model => model.itemComment)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@{
if (item.imageContent != null &&
item.imageMimeType.Contains("image"))
{
string imageBase64 =
Convert.ToBase64String(item.imageContent);
string imageSrc = string.Format("data:" +
item.imageMimeType + ";base64,{0}", imageBase64);
<img src="@imageSrc" style="max-height:100px; max-
width:120px" class="img-responsive img-rounded" />
}
}
</td>
<td>
@Html.DisplayFor(modelItem => item.Hazard.hazName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Inspection.ID)
</td>
<td>
@Html.DisplayFor(modelItem => item.itemCorrActionDue)
</td>
<td>
@Html.DisplayFor(modelItem => item.itemCorrActionCompleted)
</td>
<td>
@Html.DisplayFor(modelItem => item.itemComment)
</td>
<td>
<a href="/Items/Edit/@item.ID"><div class="glyphicon
glyphicon-pencil" style="margin-right:30px"></div></a>
<a href="/Items/Details/@item.ID"><div class="glyphicon
glyphicon-eye-open" style="margin-right:30px"></div></a>
<a href="/Items/Delete/@item.ID"><div class="glyphicon
glyphicon-remove"></div></a>
</td>
</tr>
}
</table>
<table>
@foreach (var item in Model.Inspection)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.ID)
</td>
<td>
@Html.DisplayFor(modelItem => item.SchoolID)
</td>
<td>
@Html.DisplayFor(modelItem => item.inspDate)
</td>
</tr>
}
</table>
if (Model.Count() == 0)
{
<h3>No Records Found.</h3>
<br />
<a href="/Items/Create" class="btn ncBtn">Add Item</a>
}
}
<a href="@Url.Action("DownloadPdf","Home")"> Download PDF</a>
【问题讨论】:
-
为什么不把模型引用改成这样的:
@model NCSafety.Models.Item?这样您就可以直接访问每个对象模型。
标签: c# asp.net asp.net-mvc linq