0
votes

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? })

1
The question is how to use the Html.CheckBoxFor + Bootstrap Toggle, not the Html.CheckBoxFor himself - Sparta
@Html.CheckBoxFor(model => model.Active, new { data_toggle="toggle", data_on="Yes", ..... }) (note the _ will be converted to - in the generated html) - user3559349

1 Answers

4
votes

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>