Creating a Month Dropdown in C# ASP.NET MVC

In your view model you could have a Months property:

public IEnumerable<SelectListItem> Months
{
    get 
    {
        return DateTimeFormatInfo
               .InvariantInfo
               .MonthNames
               .Select((monthName, index) => new SelectListItem
               {
                   Value = (index + 1).ToString(),
                   Text = monthName
               });
    }
}

which could be directly bound to a DropDownListFor:

<%= Html.DropDownListFor(x => x.SelectedMonth, Model.Months) %>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)