当我使用 asp.net mvc 3 脚手架制作列表时。我有一个包含表格的 View 。该表的标题在 View 中进行了硬编码。我想使用 LabelFor,所以我得到了我需要的 l10n。
我尝试做的(但失败了)是:
@model IEnumerable<User>
<table>
<tr>
<th>
@(Html.LabelFor<User, string>(model => model.Name)) <!--This line errors-->
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
</table>
它的错误是“IEnumerable 不包含名称的定义”……等等……
我如何使它工作?
最佳答案
尝试一些类似的
@(Html.LabelFor<User, string>(model => model.FirstOrDefault().Name))
关于c# - 如何在列表的强类型 View 上使用 LabelFor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6703353/