在显示数据时,有没有办法在标题中使用[DisplayName("My descriptive Name")]
而只使用列名?
(无需键入每个?) - (我使用MVC脚手架创建编辑页面)
<p>
@Html.ActionLink("Create New", "CreateTask")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
</tr>
<td>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
</tr>
}
</table>
答案 0 :(得分:0)
添加属性在此模型中显示
[Display(Name = "Your Custom Name")]
public string Name { get; set; }
在Razor View中,使用
@Html.LabelFor(model=>model.Name)
希望这能帮助你。