tags:

views:

57

answers:

1

Hi all

<%= Html.DropDownList("ServiceId",
new SelectList(Model.Services, "Id", "Name"),"-- Please Select --")%>

Is there a way to give the please select item a value of 0 or -1?

Thanks

+1  A: 

Supposing Model.Services contains list of ServiceType objects you could add an item to the list like this:

<%= 
    Html.DropDownList("ServiceId", new SelectList(
        new [] 
        {
            new ServiceType 
            {
                Id = 0,
                Name = "-- Please Select --"
            }
        }.Union(Model.Services), "Id", "Name"), 0)
%>
Alexander Prokofyev