如何通过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 关注
- 609 浏览
添加回答
举报
0/150
提交
取消