DisplayName
属性和 ASP.NET MVC 中的 Display
属性有什么区别?
最佳答案
DisplayName
在模型元数据中设置 DisplayName
。例如:
[DisplayName("foo")]
public string MyProperty { get; set; }
如果您在 View 中使用以下内容:
@Html.LabelFor(x => x.MyProperty)
它会产生:
<label for="MyProperty">foo</label>
Display
的作用相同,但还允许您设置其他元数据属性,例如名称、描述...
Brad Wilson 有一个 nice blog post涵盖这些属性。
关于c# - 显示名称属性与显示属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13271067/