MVC DropDownList与Enum Text&值

时间:2014-09-23 05:16:18

标签: asp.net-mvc enums html.dropdownlistfor

我想将DropDownlist的值设置为1,2,3,4等。&文字为1月,2月等。

以下是代码: -

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" })

我应该代替Value = e,以便DropDown列表的所有值都显示为1,2,3 ......

目前DropDown值显示为1月,2月,3月。

0 个答案:

没有答案