Home > front end >  How to add Enum Properties in ASP.NET Core 6 Identity
How to add Enum Properties in ASP.NET Core 6 Identity

Time:06-27

I want to create a dropdown to insert the gender, from Enum .

<label asp-for="Gender"></label>
    <select asp-for="Gender"  asp-items="@new SelectList(Enum.GetNames(typeof(GenderType)))">
        <option selected disabled value="Select">Select GenderType</option>
    </select>

CodePudding user response:

ASP.NET Core has built-in Html.GetEnumSelectList() method we can use to turn enum members to select list items.

            <label asp-for="Type" ></label>
            <select asp-for="Type" 
                     
                    asp-items="Html.GetEnumSelectList<EnumName>()">
                <option>Select Gender</option>
            </select>

Using Enum in .NET Core

  • Related