Is there a simple way to add a "--Please select--" default option to a DropDownListFor in MVC 3?
See Question&Answers more detail:osIs there a simple way to add a "--Please select--" default option to a DropDownListFor in MVC 3?
See Question&Answers more detail:osSo, I did something like this:
@Html.DropDownListFor(model => model.Dessert,
new SelectList(Model.AvailableDesserts, "DessertID", "DessertName"),
"---Select A Dessert ---")
Seems to work pretty well. Dessert
in my viewmodel is the one selected by the user. AvailableDesserts
is a collection of ones to pick from. Hope that helps.