In my application ASP.NET Core I pass a Checkboxlist to my view.
In my view, I have made a javascript function to select all checkboxes and unselect all checkboxes.
When my checkboxes are selected I send the form. But in my controller, any checkbox is selected.
Thanks for your help.
Javascript function
function selectAllCompta() {
var items = document.getElementsByName('myCheckBox');
var cb = document.getElementById('cbSelectAll');
var txt = document.getElementById('txtCb');
if (cb.checked) {
for (var i = 0; i < items.length; i++) {
if (items[i].type == 'checkbox')
items[i].checked = true;
}
txt.textContent = 'Déselectionner tout';
}
else {
for (var i = 0; i < items.length; i++) {
if (items[i].type == 'checkbox')
items[i].checked = false;
}
txt.textContent = 'Sélectionner tout';
}
}
View.cshtml
<input asp-for="CBC[i].Selected" name="myCheckBox" type="checkbox" class="form-control" />
Aucun commentaire:
Enregistrer un commentaire