Reputation: 1249
How can I do a @Html.DropDownListFor element non selected and with a requirer text without adding a new option element with that?
I have this code:
@Html.DropDownListFor(model => model.Description, new SelectList(ViewBag.CarsDsc, "Id", "Description"), new { @class = "iEdit"})
but I want something like this:
Upvotes: 0
Views: 82
Reputation: 79969
There is an overload for the method DropDownListFor
, that accepts an option value optionLabel
:
The text for a default empty item. This parameter can be null.
@Html.DropDownListFor(model => model.Description,
new SelectList(ViewBag.CarsDsc, "Id", "Description"),
"-Please select one-",
new { @class = "iEdit"})
Upvotes: 0