Getting attributes of Enum's value

后端 未结 25 2596
慢半拍i
慢半拍i 2020-11-22 00:35

I would like to know if it is possible to get attributes of the enum values and not of the enum itself? For example, suppose I have the following <

25条回答
  •  臣服心动
    2020-11-22 01:19

    This is how I solved it without using custom helpers or extensions with .NET core 3.1.

    Class

    public enum YourEnum
    {
        [Display(Name = "Suryoye means Arameans")]
        SURYOYE = 0,
        [Display(Name = "Oromoye means Syriacs")]
        OROMOYE = 1,
    }
    

    Razor

    @using Enumerations
    
    foreach (var name in Html.GetEnumSelectList(typeof(YourEnum)))
    {
        

    @name.Text

    }

提交回复
热议问题