Get DisplayName Attribute without using LabelFor Helper in asp.net MVC

后端 未结 3 2069
说谎
说谎 2020-11-29 19:47

What is the best way to retrieve the display name attribute for an item in your model? I see a lot of people using the LabelFor helper for everything, but a label isn\'t app

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 20:09

    In my opinion you should use a string as a result type because otherwise you skip the encoding mechanism. Another point is that you need the DisplayName in some cases as a string (i.e. populate the columns in a WebGrid class).

提交回复
热议问题