DmitryEfimenko / TwitterBootstrapMvc

Fluent implementation of ASP.NET-MVC HTML helpers for Twitter Bootstrap.
Apache License 2.0
224 stars 79 forks source link

DropDownListFromEnumFor Values are words not integers #454

Open tyronsea opened 7 years ago

tyronsea commented 7 years ago

Hi All,

Using VS2017, Bootstrap 3. TwitterBootstrapMVC5 - latest update.

Am trying to use DropDownListFromEnumFor but am finding that the Value of each item in the list box has the same text as the name of enum entry.

For example I have an enun like:

   public enum YesNo
    {
        [Display(Name = "Select an option")]
        Blank = 0,
        [Display(Name = "Yes")]
        Yes = 1,
        [Display(Name = "No")]
        No = 2
    }

The options for the select look like this:

<option value="Blank">Select an option</option>
<option selected="selected" value="Yes">Yes</option>
<option value="No">No</option>

This is not very handy as I am storing the integer value in the database and need to set the value when the form is displayed.

If I use the built in @Html.EnumDropDownListFor then the select options look like this:

<option value="0">Select an option</option>
<option selected="selected" value="1">Yes</option>
<option value="2">No</option>

I can't figure out how to make the DropDownListFromEnumFor use the integers as the values, any ideas?

Gordon