// Step 2: Bind iteration event on button click
$(document).ready(function () {
$('#iterate').click(function () {
// Get all checkboxes and filter selected ones
var checkedIds = $('input[name="selectedIds"]:checked').map(function () {
return $(this).val();
}).get();
// Do something with the selected checkboxes
console.log(checkedIds);
});
// Select all checkboxes on header checkbox click
$('#checkAll').click(function () {
$('input[name="selectedIds"]').prop('checked', this.checked);
});
});
// POST: Home/Index
[HttpPost]
public IActionResult Index(int[] selectedIds)
{
// Do something with selected Ids
return PartialView("_Grid", GetData());
}
@model IEnumerable
Demo
Name
Age
@foreach (var item in Model)
{
@item.Name
@item.Age
}