Reputation: 361
I'd like to know if it is possible to assign a default value for a Dropdownlist while restricting User to select that default value from its option list.
Example :
@Html.DropDownListFor(m => m.Something, new SelectList(Model.TheList), "--DefaultValue--", new { name="SomethingName", id="SomethingID", style="width:150px;"})
Let's suppose TheList contains {"1","2","3"}
.
When User clicks the DropDownList, he will find "--DefaultValue--"
displayed as initial value, and also find it as one of the options available to be selected.
Is it possible only to have 1,2, and 3 alone as the options without "--DefaultValue--" ?
Upvotes: 0
Views: 494
Reputation: 27
Try this:
@Html.DropDownListFor(m => m.Something, new SelectList(Model.TheList),new { name="SomethingName", id="SomethingID", style="width:150px;"})
Upvotes: 0
Reputation: 19838
The only way is to set selected value in DropDown. --Default value--
represents null
in selected value
Upvotes: 0