我正在尝试在我的 ASP.NET MVC 4 应用程序中的 html 中显示属性的显示名称。然而,即使我在视图模型中设置了显示名称,原始变量名称仍然会显示。
视图模型:
public class Manage_ManagePasswordViewModel
{
[Display(Name="Name")]
public string name;
[Display(Name = "SubID")]
public string subId;
[Display(Name = "Conversions")]
public int conversions;
[Display(Name = "Password")]
public string password;
public UserProfile owner;
public Manage_ManagePasswordViewModel(ProtectedPassword pw)
{
name = pw.Name;
subId = pw.SubId;
conversions = pw.GetConversions();
password = pw.Password;
owner = pw.Owner;
}
}
cshtml 文件:
@model Areas.Admin.Models.ViewModels.Manage_ManagePasswordViewModel
<div class="editor-label">
@Html.DisplayNameFor(m => m.name):
@Html.DisplayTextFor(m => m.name)
</div>
<div class="editor-label">
@Html.DisplayNameFor(m => m.password):
@Html.DisplayTextFor(m => m.password)
</div>
<div class="editor-label">
@Html.DisplayNameFor(m => m.subId):
@Html.DisplayTextFor(m => m.subId)
</div>
<div class="editor-label">
@Html.DisplayNameFor(m => m.conversions):
@Html.DisplayTextFor(m => m.conversions)
</div>
<div class="editor-label">
@Html.DisplayNameFor(m => m.owner.UserName):
@Html.UserLink(Model.owner.UserName, Model.owner.UserId)
</div>