mvc 5 SelectList from table with blank value for DropDownList

Use one of the overloads that accepts an optionLabel

@Html.DropDownListFor(m => m.ID, (SelectList)ViewBag.MyList, "Please select", new { @class = "form-control" })

or if you do not want to use the strongly typed methods

@Html.DropDownList("ID", (SelectList)ViewBag.MyList, "Please select", new { @class = "form-control" })

Which will add the first option with the text specified in the 3rd parameter and with a null value

<option value="">Please Select</option>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)