Html.GetEnumSelectList - Getting Enum values with spaces

后端 未结 1 1749
一个人的身影
一个人的身影 2021-01-11 13:03

I was using asp-items=\"@Html.GetEnumSelectList(typeof(Salary))\" in my Razor view with a select tag, to populate the list values based on the enum Salary

相关标签:
1条回答
  • 2021-01-11 14:00

    I managed to solve it. I just had to use the other method of GetEnumSelectList<>, and in the Razor view we need to use the Display attribute.

    Here is the code:

    Razor View:

    <select asp-for="PersonSalary" asp-items="Html.GetEnumSelectList<Enums.Salary>()"></select>
    

    Enum Salary:

    public enum Salary
    {
        [Display(Name="Paid Monthly")]
        PaidMonthly = 1,
        PaidYearly = 2
    } 
    
    0 讨论(0)
提交回复
热议问题