How to get the Display Name Attribute of an Enum member via MVC razor code?

后端 未结 20 2853
孤街浪徒
孤街浪徒 2020-11-22 09:30

I\'ve got a property in my model called \"Promotion\" that its type is a flag enum called \"UserPromotion\". Members of my enum have display attributes set as follows:

20条回答
  •  甜味超标
    2020-11-22 09:52

      @foreach (int aPromotion in @Enum.GetValues(typeof(UserPromotion))) { var currentPromotion = (int)Model.JobSeeker.Promotion; if ((currentPromotion & aPromotion) == aPromotion) {
    • @Html.DisplayFor(e => currentPromotion)
    • } }

提交回复
热议问题