Sérgio Ribeiro
Sérgio Ribeiro

Reputation: 51

How to set new attribute to a @Html.DropDownListFor

I'm trying to add an specific attribute (data-toggle="select") to my DropDownListFor.

When I use:

@Html.DropDownListFor(model, myList, "Select..", new { @class = "form-control", @data-toggle="select" }). 

I get the error saying that "Cannot resolve symbol 'data'" and "Cannot resolve symbol 'toggle'"

What can I do so my DropDownListFor recognizes the attribute data-toggle?

Ps: When I use

@Html.DropDownListFor(model, myList, "Select..", new { @class = "form-control"})

it works just fine

Upvotes: 0

Views: 479

Answers (1)

Darkpaladin
Darkpaladin

Reputation: 46

The answer is actually pretty simple, just replace your -(dash) with a _(underscore) and you will be set.

@Html.DropDownListFor(model, myList, "Select..", new { @class = "form-control", @data_toggle="select" }).

Upvotes: 3

Related Questions