I have the following razor syntax for creating a dropdown list from a list of objects.
@Html.DropDownListFor(m => m.data_connection,
new SelectList( Model.connections,
"ID", "Title",
Model.data_connection) ,
new { style = "width: 420px;" })
This works, but I'd like to add a - select a connection -
style dummy entry to the top of the list. I can do this by passing a SelectList
instead of my collection of objects, but I'm wondering if there's a nice easy way to do this in the view?
Doh, found the answer here
@Html.DropDownListFor(m => m.data_connection,
new SelectList( Model.connections,
"ID", "Title",
Model.data_connection) ,
" -- select a connection -- ",
new { style = "width: 420px;" })