ID
Products
Time Posted
Status
@for (int i = 0; i < Model.Items.Count; i++)
{
@Html.DisplayFor(modelItem => Model.Items.Id)
@Html.DisplayFor(modelItem => Model.Items.ProductName)
@Html.DisplayFor(modelItem => Model.Items.Time_Posted)
@Html.CheckBoxFor(modelItem => Model.Items.Status, new { @class = "toggle-checkbox", data_id = Model.Items.Id })
}
var url = '@Url.Action("UpdateStatus")';
$('.toggle-checkbox').click(function () {
var isChecked = $(this).is(':checked'); //CheckBox checked - True or false
var id = $(this).data('id'); //Get the id of that specific checked row
$.post(url, { id: id, status: isChecked }, function (response) {
if (response) {
alert("Status changed");
}
})
});
$(document).ready(function () {
$('.toggle-checkbox').btnSwitch({ //This is the script for toggling
Theme: 'Light',
OnText: "On",
OffText: "Off",
OnValue: true,
OffValue: false
});
});
Подробнее здесь: https://stackoverflow.com/questions/455 ... e-switches