1

Okay I have searched it long enough to not find this anywhere on the net. So here is my question, in asp.net MVC (5.1) razor the default helper we can use DisplayNameFor to get the Name value from Display attribute is there anything similar for retrieving Description?

[Display(Name = "First Name", Description="What is your first name")]
public string FirstName { get; set; }

E.g.

@Html.DisplayNameFor(model=>model.FirstName) 
Sanj
  • 3,770
  • 6
  • 26
  • 31
  • 2
    you may refer to here http://stackoverflow.com/questions/6578495/how-do-i-display-the-displayattribute-description-attribute-value – card_master Mar 26 '14 at 08:00

1 Answers1

1

Instead use LabelFor and try below code.

  @Html.LabelFor(m => m.FirstName, 
    new{title=ModelMetadata.FromLambdaExpression<Models.Profile, string>
    (m => m.FirstName, ViewData).Description})
Ashwini Verma
  • 7,477
  • 6
  • 36
  • 56