WorknHardr
asked on
SelectList using DateTimeFormatInfo CurrentInfo GetMonthName?
I trying to build a SelectList using the System.Globalization.DateT imeFormatI nfo.Curren tInfo.GetM onthName enumeration. The code works without error, just not loading the DropDownListFor correctly. As you might expect it looks like this:
{ I = 1, M = January }
{ I = 2, M = February }
etc...
I thought it would be nice to build it as a single-line-of-code like I did for a YearSelectList like so:
YearsSelectList = new SelectList(Enumerable.Rang e(DateTime .Today.Yea r, 15))
Here's my current code...
{ I = 1, M = January }
{ I = 2, M = February }
etc...
I thought it would be nice to build it as a single-line-of-code like I did for a YearSelectList like so:
YearsSelectList = new SelectList(Enumerable.Rang
Here's my current code...
[Action]
MonthsSelectList = new SelectList(Enumerable.Range(1, 12).Select(i => new { I = i, M = System.Globalization.DateTimeFormatInfo.CurrentInfo.GetMonthName(i) }))
[View]
@Html.DropDownListFor(model => model.MonthId, new SelectList(Model.MonthsSelectList, "Value", "Text"), "-select-")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER