1

All I want to know is the proper syntax for using Bootstrap Toggle with the Html.CheckBoxFor HTML helper in ASP.NET MVC.

< input type="checkbox" checked data-toggle="toggle" data-on="Yes" data-off="No" data-width="15" data-height="15" data-onstyle="success" data-offstyle="danger" data-style="ios">

The question is how to use the Html.CheckBoxFor + Bootstrap Toggle, not the Html.CheckBoxFor himself

@Html.CheckBoxFor(model => model.Active, new { ?Bootstrap Toggle? })

Sparta
  • 25
  • 1
  • 6
  • https://stackoverflow.com/questions/12674572/proper-usage-of-net-mvc-html-checkboxfor Duplicate? – Alejandro May 17 '18 at 13:22
  • 1
    Possible duplicate of [Proper usage of .net MVC Html.CheckBoxFor](https://stackoverflow.com/questions/12674572/proper-usage-of-net-mvc-html-checkboxfor) – FilipRistic May 17 '18 at 13:24
  • 1
    The question is how to use the Html.CheckBoxFor + Bootstrap Toggle, not the Html.CheckBoxFor himself – Sparta May 17 '18 at 13:31
  • 2
    `@Html.CheckBoxFor(model => model.Active, new { data_toggle="toggle", data_on="Yes", ..... })` (note the `_` will be converted to `-` in the generated html) –  May 18 '18 at 00:27

1 Answers1

4

I have a list of checkbox and use Bootstrap Toggle like that:

@Html.CheckBoxFor(x => item.isSelected, new { id = "espSelected_" + 
  item.idEspecialidad, data_toggle = "toggle", data_onstyle = "success" })

Do not forget to use this:

<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" 
    rel="stylesheet">
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
tschmit007
  • 7,559
  • 2
  • 35
  • 43