GibboK
GibboK

Reputation: 73938

how to add a static element to @Html.DropDownListFor

I use this code to display a drop down menu list in my View, I would like to add a STATIC value at the beginning of the List with text like None and value as "". How to do it in Razor?

  @Html.DropDownListFor(modal => modal.Candidates, new SelectList(Model.Candidates, "Value", "Key"))

Upvotes: 0

Views: 233

Answers (1)

StuartLC
StuartLC

Reputation: 107277

There is an overload of DropDownListFor which takes on a default string, e.g.

 @Html.DropDownListFor(modal => modal.Candidates, 
                       new SelectList(Model.Candidates, "Value", "Key"), 
                       "None")

Upvotes: 3

Related Questions