0

What is the difference between these 2 Display attributes?

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

These are inside a buddy metadata class using mvc5 and EF 6 in VS2012.

The first one will throw this message.

enter image description here

user1307149
  • 1,427
  • 2
  • 16
  • 30

1 Answers1

3

Possible duplicate:

displayname attribute vs display attribute

DisplayName sets the DisplayName in the model metadata. For example:

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

and if you use in your view the following:

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

it would generate:

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

Display does the same, but also allows you to set other metadata properties such as Name, Description

Community
  • 1
  • 1
aamir sajjad
  • 3,019
  • 1
  • 27
  • 26