I have this check box which helps me to send a value to the controller:
@Html.CheckBoxFor(m => m.sendvalue, htmlAttributes: new { @id = "sendvalue" })
I'm having trouble figuring out how to change the check box to a toggle on/off switch.
The code for the toggle button (I don't understand how to send the value to the controller using toggle):
<input id="sendvalue" class="cmn-toggle cmn-toggle-round" type="checkbox" aria-label="sendvalue" >
<label for="sendvalue"></label>
CSS:
.cmn-toggle {
position: absolute;
margin-left: -9999px;
visibility: hidden;
}
.cmn-toggle + label {
display: block;
position: relative;
cursor: pointer;
outline: none;
user-select: none;
}
input.cmn-toggle-round + label {
padding: 2px;
width: 45px;
height: 22.5px;
background-color: #dddddd;
border-radius: 22.5px;
}
input.cmn-toggle-round + label:before,
input.cmn-toggle-round + label:after {
display: block;
position: absolute;
top: 1px;
left: 1px;
bottom: 1px;
content: "";
}
input.cmn-toggle-round + label:before {
right: 1px;
background-color: #f1f1f1;
border-radius: 22.5px;
transition: background 0.4s;
}
input.cmn-toggle-round + label:after {
width: 21.75px;
background-color: #fff;
border-radius: 100%;
box-shadow: 0 0.75px 1.825px rgba(0, 0, 0, 0.3);
transition: margin 0.4s;
}
input.cmn-toggle-round:checked + label:before {
background-color: #6C9F2E;
}
input.cmn-toggle-round:checked + label:after {
margin-left: 22.75px;
}
forto bind events on lable to checkbox