Murtaza Munshi
Murtaza Munshi

Reputation: 1085

Set Dropdown value to null when Page Loads MVC

I have created a DropDwonList in MVC like this

@Html.DropDownListFor(x => x.Item2.DeliveryDetail.PackageTypeId, new SelectList(lstPackageTypes, "PackageTypeId", "PackageTypeName"),new {@class = "cstm-input", @placeholder = "Package Type"})

It generates a DropDown but by default the first Item is selected when page loads. I want that the dropdown should be un-selected and the user should be allowed to select a value from it.

Thanx in Advance.

Upvotes: 0

Views: 523

Answers (1)

Bhushan Firake
Bhushan Firake

Reputation: 9448

You can specify the default OptionLabel with overload method of DropDownListFor as below:

 @Html.DropDownListFor(x => x.Item2.DeliveryDetail.PackageTypeId, 
 new SelectList(lstPackageTypes, "PackageTypeId", "PackageTypeName"),
 "--Select Package Type--",
 new {@class = "cstm-input", @placeholder = "Package Type"})

Upvotes: 2

Related Questions