0

I want to set values of DropDownlist to 1, 2, 3, 4 , etc. & text as January, february, etc.

Following is the code:-

public enum InputMonths
    {
        January = 1,
        February = 2,
        March = 3,
        April = 4,
        May = 5,
        June = 6,
        July = 7,
        August = 8,
        September = 9,
        October = 10,
        November = 11,
        December = 12
    }

@Html.DropDownListFor(model => model.ApplyMonth, Enum.GetNames(typeof(Models.InputMonths)).Select(e => new SelectListItem { Text = e, Value = e }), "-- Select Month --", new { @class = "form-control", @id = "ApplyMonth" })

What should i put in place of Value = e so that all values of DropDown list should show 1, 2, 3...

Currently DropDown values show as January, February, March.

tereško
  • 58,060
  • 25
  • 98
  • 150
Anup
  • 9,396
  • 16
  • 74
  • 138
  • Creating an extension method as per [this answer](http://stackoverflow.com/questions/388483/how-do-you-create-a-dropdownlist-from-an-enum-in-asp-net-mvc) may be easier –  Sep 23 '14 at 05:27
  • maybe this will help http://stackoverflow.com/questions/20111231/create-a-list-of-key-value-pairs-using-key-enums-name-and-value-enums-value – Matt Bodily Sep 23 '14 at 14:42

0 Answers0