Default option label for DropDownList in ASP.NET MVC Preview 5

The ASP.NET MVC Preview 5 has provided the functionality to add a default option label for DropDownList control. For adding a default option label, provide the default label as the first argument of the DropDownList helper method. This will render the default option label element with its value attribute equal to an empty string, but with its inner text as the value that you provide.

<%=Html.DropDownList("--Select Customer--","Customer") %>
Published Monday, September 01, 2008 3:55 AM by shiju
Filed under: ,

Comments

# funny wallpaper &raquo; Default option label for DropDownList in ASP.NET MVC Preview 5

Pingback from  funny wallpaper &raquo; Default option label for DropDownList in ASP.NET MVC Preview 5

# ASP.NET MVC Archived Blog Posts, Page 1

Monday, September 01, 2008 3:08 PM by ASP.NET MVC Archived Blog Posts, Page 1

Pingback from  ASP.NET MVC Archived Blog Posts, Page 1

# re: Default option label for DropDownList in ASP.NET MVC Preview 5

Monday, October 13, 2008 5:28 PM by Jared

How do you get it so a blank option will show in the list? If I put a string.Empty there it doesn't add the blank option.

# re: Default option label for DropDownList in ASP.NET MVC Preview 5

Tuesday, April 28, 2009 12:50 AM by nie

cool

# re: Default option label for DropDownList in ASP.NET MVC Preview 5

Tuesday, May 05, 2009 1:17 PM by Maria

well, i have being looking for information about how to use a dropdownlist in asp.net mvc and the answer is always the same, and the problem that i have is that when i run the application in VS , it´s send to me and error that say "que no se encontro ningun metodo de extensión en DropdownList" if someone can help me please do.

my email is tere-1512@hotmail.com

# re: Default option label for DropDownList in ASP.NET MVC Preview 5

Wednesday, May 06, 2009 9:16 AM by www.almny.com

where's the example

# re: Default option label for DropDownList in ASP.NET MVC Preview 5

Thursday, October 08, 2009 3:19 PM by cshellvb

Ok when I first read this I was ready to complain :P

I thought this empty string would break my Binding in the Controller method for int types that are linked to the drop down.

Then I tested it real quick to get the error for complaining....

Dangit - it returns 0, just like I wanted.

Is this just some black magic in the background that is doing a cast from empty.string to 0 in the background ?

# re: Default option label for DropDownList in ASP.NET MVC Preview 5

Monday, October 12, 2009 3:39 AM by r4 firmware

How do you get it so a blank option will show in the list? If I put a string.Empty there it doesn't add the blank option.

# re: Default option label for DropDownList in ASP.NET MVC Preview 5

Wednesday, November 18, 2009 5:14 PM by Joanna

Add <asp:ListItem></asp:ListItem> like this <asp:DropDownList><asp:ListItem></asp:ListItem></asp:DropDownList>

This works whether you are using static values or dynamic values

Leave a Comment

(required) 
(required) 
(optional)
(required)