这2个显示属性之间的区别?

时间:2014-05-11 18:06:35

标签: c# asp.net-mvc-4 asp.net-mvc-5

这两个显示属性有什么区别?

[Required]
[DisplayName("Status")]
[Display(Name = "Status")]
public string StatusName;

这些是在VS2012中使用mvc5和EF 6的伙伴元数据类。

第一个将抛出此消息。

enter image description here

1 个答案:

答案 0 :(得分:3)

可能重复:

displayname attribute vs display attribute

DisplayName在模型元数据中设置DisplayName。例如:

[DisplayName("foo")]
public string MyProperty { get; set; }

如果您在视图中使用以下内容:

@Html.LabelFor(x => x.MyProperty)

它会产生:

<label for="MyProperty">foo</label>

显示相同,但​​也允许您设置其他元数据属性,如名称,描述

相关问题