clement
clement

Reputation: 4266

radiobuttonfor with data- with strange behaviour

i'm trying to make a checkbox with bool value from my model. it works, but now I'm trying to add some data-* field to the checkbox In order to add parameters to the nice bootstrap-switch component, and it doesn't work:

<input data-val="true" id="actionList_0__efficacity" name="actionList[0].efficacity" type="radio" value="{ data_on_text = YEAH}">

And it should be

<input data-val="true" id="actionList_0__efficacity" name="actionList[0].efficacity" type="radio" data-on-text = "YEAH">

so this is what I've done:

@Html.RadioButtonFor(x => x.efficacity, new { data_on_text = "YEAH" } )

I already tried the EditorFor for I can't put data_ with EditorFor apparently...

Thanks for the help

Upvotes: 0

Views: 90

Answers (1)

user3559349
user3559349

Reputation:

The html and the helper you have shown don't quite match up (the html suggests your generating radio buttons for a collection because it contains an indexer or perhaps you have an EditorTemplate for the type represented by property actionList?) but the 2nd parameter of RadioButtonFor() is the object that sets the 'value' attribute. You need to change the helper to

@Html.RadioButtonFor(x => x.efficacity, someValue, new { data_on_text = "YEAH" } )

where someValue is the value that will be assigned to property efficacity (for example a string or an enum)

Upvotes: 1

Related Questions