2014-05-11 27 views
0

这2个显示属性有什么区别?这两个显示属性之间的区别?

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

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

第一个会抛出此消息。

enter image description here

回答

3

可能重复:

displayname attribute vs display attribute

显示名称设置模型中的元数据显示名称。例如:

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

,如果你在你的视图中使用下列内容:

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

它会产生:

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

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