liveBook · Manning

GetEnumSelectList

As explained in ASP.NET Core in Action, 3e

GetEnumSelectList is an ASP.NET Core HTML helper method that creates select-list items for the values of an enumeration type.

GetEnumSelectList<TEnum>() creates an IEnumerable<SelectListItem> for every value in an enumeration. Use the result with the Select Tag Helper’s asp-items attribute instead of writing the enum-to-option mapping yourself. section 18.2.4 section 18.6

Populate a select from an enum

<select asp-for="Input.SelectedValue" asp-items="Html.GetEnumSelectList<TEnum>()"></select> The bound property receives the selected enum value, while the helper supplies the available option items. section 18.2.4 section 18.6

The generated items can support the same select-list patterns as other SelectListItem collections, including drop-downs, list boxes, and multiple-selection controls when the bound property is an IEnumerable. section 18.2.4

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains the helper’s purpose and usage, but does not detail its internal option-generation implementation.
Examples
Uses Html.GetEnumSelectList<TEnum>() inside a select element’s asp-items attribute.
What it assumes
Assumes familiarity with enum types, Razor select elements, and the asp-for and asp-items attributes.
What you can do after
Apply it via Razor to render enum choices without manually mapping values to SelectListItem objects.
How it connects
Connects enum values with SelectListItem, Select Tag Helper, Razor, and model binding.

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.