Lovepreet Singh
Lovepreet Singh

Reputation: 73

how to add style in Dropdownlistfor helper in mvc?

Want to add style with onchange function in dropdownlist my code is something like this :-

 @Html.DropDownListFor(m=>m.printEmployeeCardDTO.DataCardConnectionType,null,new {    @onchange="_printEmployeeCard.GetPrintersDetail(this.value, printersList);" },new    { style = "width: 100px;" }  )

I m getting error in this. Could anyone help me in it?

Upvotes: 1

Views: 4673

Answers (2)

user5966947
user5966947

Reputation: 21

Use the @ sign with the style attribute, like this:

@style = "width: 100px;"

Upvotes: 2

Orel Eraki
Orel Eraki

Reputation: 12196

You used two different parameters new { } instead of only one separated by ,

@Html.DropDownListFor(
    m => m.printEmployeeCardDTO.DataCardConnectionType,
    null,
    new { @onchange="_printEmployeeCard.GetPrintersDetail(this.value, printersList);", style = "width: 100px;" }
)

Upvotes: 2

Related Questions