Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc How to add placeholder for html.dropdownlist

I'm using asp.net mvc 3.

I have this dropdownlist of countries and I want to add a placeholder for it. Here's my code:

@Html.DropDownList("country",
     new SelectList(ViewBag.countries as System.Collections.IEnumerable,
     "name", "name"), new { @class="chzn-select", @placeholder="-select-",
     @style="width:160px;" } )

But the placeholder doesn't work, while the style works.

How do I set a placeholder for this?

PS. I just want to use @Html.DropDownList, not @Html.DropDownListFor

like image 206
user2093360 Avatar asked Apr 18 '13 02:04

user2093360


1 Answers

You could try this:

@Html.DropDownList("country", new SelectList(ViewBag.countries), "-select- ", new { @class="chzn-select", @style="width:160px;" })
like image 96
Ovidiu G Avatar answered Oct 13 '22 01:10

Ovidiu G