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
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
}