Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add Enum Properties in ASP.NET Core 6 Identity

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

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

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

Using Enum in .NET Core

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading