Adding global blank option to DroDownList in MVC

Posted by Diegos Grace on Stack Overflow See other posts from Stack Overflow or by Diegos Grace
Published on 2010-05-26T02:21:56Z Indexed on 2010/05/26 3:21 UTC
Read the original article Hit count: 270

Filed under:
|
|

Is there a way of using a templated helper in mvc so that each and every select list in my project has a custom default 'Choose an option' with null value etc.

The posts I have seen seem a little complex, is it possible to have a DropDownList.ascx file in shared view folder with something like this:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<SelectListItem>>" %>
<%= Html.DropDownList(selectlist name, selectlist value, "Choose an option")%>

And then having a UIHint("DropDownList") for each dropdownlist in the ViewModel? Some guidance on syntax of parameters would be much appreciated, where name and value of the viewmodel dropdownlist plus the 'Choose an option' string are passed.

Or is this all wishful thinking?

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc-2