@Html.DropDownListFor How to add option?

Shane LeBlanc picture Shane LeBlanc · Feb 15, 2012 · Viewed 27.9k times · Source
@Html.DropDownListFor(model => model.ZipFile, new SelectList(ViewBag.ZipFiles))

The above code creates me a select list just fine. But I want to make the selection optional. Unfortunately there is no empty option and I'd like to add one in. How would I do this?

Answer

Darin Dimitrov picture Darin Dimitrov · Feb 15, 2012

By using the proper DropDownListFor overload:

@Html.DropDownListFor(
    model => model.ZipFile, 
    new SelectList(ViewBag.ZipFiles),
    "-- please select a zip file --"
)