我的模型中有一个名为“ Promotion”的属性,其类型是一个名为“ UserPromotion”的标志枚举。我的枚举成员的显示属性设置如下:
[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>
System.ComponentModel.DataAnnotations.DisplayAttribute
。不System.ComponentModel.DisplayNameAttribute
。