# Populating a Form DropDownList with Enum Values

## Environment

<table>
    <tbody>
        <tr>
            <td>Product Version</td>
            <td>2023.1.314</td>
        </tr>
        <tr>
            <td>Product</td>
            <td>DropDownList for ASP.NET MVC</td>
        </tr>
    </tbody>
</table>

## Description

I want to populate a Telerik UI for ASP.NET MVC DropDownList editor of a Form with the Enum values and bind them to the model. How can I do this?

## Solution

To achieve the desired results:

1. Use the [`Html.GetEnumSelectList<TEnum>()`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.viewfeatures.htmlhelper.getenumselectlist?view=aspnetcore-7.0#microsoft-aspnetcore-mvc-viewfeatures-htmlhelper-getenumselectlist-1) to get the `SelectList` of the available options.

2. Use the `BindTo()` configuration of the DropDownList to bind to the returned `SelectList`.

Refer to [this REPL example](https://netcorerepl.telerik.com/mxORFgEN03Pjpclo16) for a runnable demo of the snippet below:

```
@using System.ComponentModel 
@functions{
    public enum Difficulty { Easy, Normal, Hard }

    public class MyModel
    {
        public string Name {get;set;}
        public Difficulty SelectedOption {get; set;}
    }
}

@{
    var modelData = new MyModel(){Name = "Player 1", SelectedOption = Difficulty.Normal};
}

@(Html.Kendo().Form<MyModel>()
        .Name("exampleForm")
        .FormData(modelData)
        .HtmlAttributes(new { action = "Items", method = "POST" })
        .Validatable(v =>
        {
            v.ValidateOnBlur(true);
            v.ValidationSummary(vs => vs.Enable(true));
        })
        .Items(items =>
        {
            items.AddGroup()
                .Label("Choose Game settings")
                .Items(i =>
                {
                    i.Add()
                         .Field(f => f.Name)
                         .Label(l => l.Text("Player Name:"));

                    i.Add()
                        .Field(f => f.SelectedOption)
                        .Label(l => l.Text("Difficulty:"))
                        .Editor(e =>
                        {
                            e.DropDownList()
                                .DataTextField("Text")
                                .DataValueField("Value")
                                .Height(520)
                                .BindTo(Html.GetEnumSelectList<Difficulty>());  
                        });
                });
        })
    )

```

## More ASP.NET MVC DropDownList Resources

* [ASP.NET MVC DropDownList Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/editors/dropdownlist/overview)

* [ASP.NET MVC DropDownList Demos](https://demos.telerik.com/aspnet-mvc/dropdownlist)

* [ASP.NET MVC DropDownList Product Page](https://www.telerik.com/aspnet-mvc/dropdownlist)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Telerik REPL: Populating a Form DropDownList with Enum Values](https://netcorerepl.telerik.com/mxORFgEN03Pjpclo16)
* [Client-Side API Reference of the DropDownList for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/dropdownlist)
* [Server-Side API Reference of the DropDownList for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/dropdownlist)
* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)
* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
