Umair Rana
Umair Rana

Reputation: 683

Add class in dropdown list

@Html.DropDownListFor(m => m.Baled, new SelectList(new [] {"Select Type","Option1", "Option2", "Option3"})) 

I want to add a css class in the dropdown list.

I have tried this

  @Html.DropDownListFor(m => m.Baled, new SelectList(new [] {"Select Type","Option1", "Option2", "Option3"}, new {@class="myclass"}))

But it doesn't work

If anyone can suggest me any other better way to display dropdown list will be ok too.

Upvotes: 0

Views: 41

Answers (1)

Rashmin Javiya
Rashmin Javiya

Reputation: 5222

You have close the bracket at wrong place. you have defined attribute in second paramter of selectlist. actually it should be close first and define in the last parameter of Html.DropDownListFor

@Html.DropDownListFor(m => m.Baled, new SelectList(new[] { "Select Type", "Option1", "Option2", "Option3" }), new { @class = "myclass" })

Upvotes: 2

Related Questions