this is my drop down list:
@Html.DropDownListFor(m => m.ReportType, new SelectList(ViewBag.DateRange as List<SelectListItem>, "Value", "Text"), new { @class = "w150" })
I cannot figure out where to put the default value in there? My default value would be 'ThisMonthToDate'
Any suggestions?
If you have a Model bounded to your view, I strongly recommend you to avoid using
ViewBag
and instead add aProperty
to your Model/ViewModel to hold the Select List Items. So your Model/ViewModel will looks like thisThen in your GET Action method, you can set the value , if you want to set one select option as the default selected one like this
and in your Strongly typed view ,
The HTML Markup generated by above code will have the HTML select with the option with value 2 as
selected
one.