为了账号安全,请及时绑定邮箱和手机立即绑定

如何通过MVC剃须刀代码获得Enum成员的显示名称属性?

如何通过MVC剃须刀代码获得Enum成员的显示名称属性?

凤凰求蛊 2019-07-10 14:40:15
如何通过MVC剃须刀代码获得Enum成员的显示名称属性?我在我的模型中有一个名为“促销”的属性,它的类型是一个名为“User促销”的标志枚举。Myenum成员的显示属性设置如下:[Flags]public enum UserPromotion{     None = 0x0,     [Display(Name = "Send Job Offers By Mail")]     SendJobOffersByMail = 0x1,     [Display(Name = "Send Job Offers By Sms")]     SendJobOffersBySms = 0x2,     [Display(Name = "Send Other Stuff By Sms")]     SendPromotionalBySms = 0x4,     [Display(Name = "Send Other Stuff By Mail")]     SendPromotionalByMail = 0x8}现在,我希望能够在我的视图中创建一个ul,以显示我的“促销”属性的选定值。这就是我到目前为止所做的工作,但问题是如何在这里获得显示名称?<ul>     @foreach (int aPromotion in @Enum.GetValues(typeof(UserPromotion)))     {         var currentPromotion = (int)Model.JobSeeker.Promotion;         if ((currentPromotion & aPromotion) == aPromotion)         {         <li>Here I don't know how to get the display attribute of "currentPromotion".</li>         }     }</ul>
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 630 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号