jeanre
jeanre

Reputation:

ASP.NET MVC DropDownLists

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

Thanks

Upvotes: 0

Views: 96

Answers (1)

Alexander Prokofyev
Alexander Prokofyev

Reputation: 34523

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)
%>

Upvotes: 1

Related Questions