@Html.CheckBoxFor adding a free text

432 views Asked by At

I got an HTML file from design with following code:

<input type="checkbox" data-switchery checked name="product_edit_active_control" id="product_edit_active_control" />

how to create this using MVC's @Html.CheckBoxFor(model => I know how to add a new attribute using e.g. new { @class = "longInputForEdit" }

but how to add non attribute in my case data-switchery

2

There are 2 answers

0
Mihail Stancescu On BEST ANSWER

You could try it like this:

@Html.CheckBoxFor(model => model.Property, new { @class="", data_switchery=""})
0
Alexander V. On

You could use new { @class = "longInputForEdit", data_switchery="attr value" } complete example:

@Html.CheckBoxFor(model => model.Name, new { @class="", data_switchery="attribute value"})

so you could use _ for any attribute with - in it like some_val will be some-val