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