好的,所以我通常在我的视图中使用 foreach 来在表格中显示数据。我最近发现 DisplayFor 可以使用 DisplayTemplate 为我做到这一点。问题是如何为表创建标题。以下代码显然会为每个 FooPermissionModel 模型创建一个标头:
@model StackExamples.Models.FooPermissionModel
<table>
<thead>
<tr>
<th>
Heading 1
</th>
<th>
Heading 2
</th>
<th>
Heading 3
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
@Html.DisplayFor(x => x.Field1)
</td>
<td>
@Html.DisplayFor(x => x.Field2)
</td>
<td>
@Html.DisplayFor(x => x.Field3)
</td>
</tr>
</tbody>
</table>
我可以将表头放在主视图上,但肯定有更好的方法吗?
非常感谢任何帮助。