Skip to content Skip to sidebar Skip to footer

Html.getenumselectlist - Getting Enum Values With Spaces

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. However, my enum contains

Solution 1:

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:

publicenum Salary
{
    [Display(Name="Paid Monthly")]
    PaidMonthly = 1,
    PaidYearly = 2
} 

Post a Comment for "Html.getenumselectlist - Getting Enum Values With Spaces"