WorknHardr
asked on
MVC DropDownListFor SelectList Default Selected Value Issues?
Very strange, this DropDownListFor looks correct on page load, displays 'This Year'. Problem becomes apparent after clicking the dropdown arrow to displays this:
[View Page Source]
The DropDownListFor worked great until I added the 'selectedValue' pararm like so:
@Html.DropDownListFor(mode l=> model.date, new SelectList(Model.dpSearchL ist, "Value", "Text", 4), "This Year", new { id = "ddlDate", @class = "form-control" })
Here's the hard-coded SelectList:
{ ID = "1", Name = "Today"}
{ ID = "2", Name = "This week"}
{ ID = "3", Name = "This month"}
{ ID = "4", Name = "This year"}
{ ID = "5", Name = "All time"}
[View Page Source]
<div>
<select class="form-control" id="ddlDate" name="date"><option value="">This Year</option>
<option value="">{ ID = 1, Name = Today }</option>
<option value="">{ ID = 2, Name = This week }</option>
<option value="">{ ID = 3, Name = This month }</option>
<option value="">{ ID = 4, Name = This year }</option>
<option value="">{ ID = 5, Name = All time }</option>
</select>
</div>
The DropDownListFor worked great until I added the 'selectedValue' pararm like so:
@Html.DropDownListFor(mode
Here's the hard-coded SelectList:
dpSearchList = new SelectList(new[]{
new{ ID = "1", Name = "Today"},
new{ ID = "2", Name = "This week"},
new{ ID = "3", Name = "This month"},
new{ ID = "4", Name = "This year"},
new{ ID = "5", Name = "All time"}});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER