1

I want to use @Html.CheckBoxFor to produce this HTML:

<input checked="checked" data-val="true" id="IsActive" name="IsActive" data-off="Inactive" data-on="Active" type="checkbox" value="true">

If I use:

@Html.CheckBoxFor(m => m.IsActive, new {  data-on="Active", data-off="Inactive" })

My code does not compile.

and if I use:

@Html.CheckBoxFor(m => m.IsActive, new {  on="Active", off="Inactive" })

I don't get the expected: data-off="Inactive" data-on="Active" in the output HTML.

The reason I need data-on and data-off is that, it is what my library bootstraptoggle is expecting.

  • `new { data_on="Active", data_off="Inactive }` - you need to use an underscore (which will then be converted to a hyphen in the generated html –  Mar 07 '18 at 22:53
  • Thanks a lot Stephen, it worked. –  Mar 07 '18 at 22:57

0 Answers0