如何通過(guò)MVC剃須刀代碼獲得Enum成員的顯示名稱屬性?我在我的模型中有一個(gè)名為“促銷”的屬性,它的類型是一個(gè)名為“User促銷”的標(biāo)志枚舉。Myenum成員的顯示屬性設(shè)置如下:[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}現(xiàn)在,我希望能夠在我的視圖中創(chuàng)建一個(gè)ul,以顯示我的“促銷”屬性的選定值。這就是我到目前為止所做的工作,但問(wèn)題是如何在這里獲得顯示名稱?<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 回答
- 0 關(guān)注
- 629 瀏覽
添加回答
舉報(bào)
0/150
提交
取消