Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Html.DropDownListFor How to add option?

Tags:

@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?

like image 824
Shane LeBlanc Avatar asked Feb 15 '12 12:02

Shane LeBlanc


1 Answers

By using the proper DropDownListFor overload:

@Html.DropDownListFor(     model => model.ZipFile,      new SelectList(ViewBag.ZipFiles),     "-- please select a zip file --" ) 
like image 187
Darin Dimitrov Avatar answered Sep 18 '22 19:09

Darin Dimitrov