我在为Product
创建编辑和模板时遇到此错误。
Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
编辑在我的Razor视图中:
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Select(m => m.ProductID))
</th>
<th>
@Html.DisplayFor(model => model.Select(m => m.Name))
</th>
<th>
@Html.DisplayFor(model => model.Select(m => m.ListPrice))
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.ProductID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.ListPrice)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ProductID }) |
@Html.ActionLink("Details", "Details", new { id=item.ProductID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ProductID })
</td>
</tr>
}
</table>
你知道这是什么意思以及如何解决它吗?非常感谢你!
答案 0 :(得分:0)
这不起作用吗?
<th> @Html.DisplayFor(model => model.ProductID) </th>
编辑,尝试这样的事情:
<table id="myTable">
<tr>
<th>
@Html.DisplayNameFor(model => model.ProductID)
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.ProductID)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProductID)
</td>
</tr>
}
</table>