【发布时间】:2014-03-28 07:47:36
【问题描述】:
我在为 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>
您知道这意味着什么以及如何解决它吗?非常感谢!
【问题讨论】:
-
您想为模型中的每个
ProductID生成一个<th>吗? -
@TrungPham 出于什么原因?这是带有标题的简单表格,通常不会与这 3 个选择一起使用。你期望的结果是什么?
DisplayFor为Enumerable<>?
标签: asp.net-mvc razor