首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何通过MVC Razor代码获取Enum成员的显示名称属性?

如何通过MVC Razor代码获取Enum成员的显示名称属性?
EN

Stack Overflow用户
提问于 2012-10-27 19:38:04
回答 14查看 327.6K关注 0票数 247

我的模型中有一个名为Promotion的属性,它的类型是一个名为UserPromotion的标志枚举。我的枚举成员的显示属性设置如下:

代码语言:javascript
复制
[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来显示我的Promotion属性的选定值。这就是我到目前为止所做的,但问题是,我如何才能在这里获得显示名称?

代码语言:javascript
复制
<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>
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13099834

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档