Hi @Ahmed Abd El Aziz
From your code and description, I think you want to send the selected value to the OnPost method using JQuery Ajax method, right? If that is the case, refer to the following sample:
Program.cs file: register the Antiforgery:
builder.Services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");
Reprintslist.cs
public class Reprintslist
{
public int id { get; set; }
public DateTime LoggedDate { get; set; }
public string OrderType { get; set; }
public int OrderNo { get; set; }
public string PrinterName { get; set; }
public string BranchCode { get; set; }
public string Status { get; set; }
}
ReprintsIndex.cshtml.cs page:
public class ReprintsIndexModel : PageModel
{
[BindProperty]
public List<Reprintslist> Reprintslist { get; set; }
public void OnGet()
{
Reprintslist = GetReprintslists();
}
public List<Reprintslist> GetReprintslists()
{
return new List<Reprintslist>()
{
new Reprintslist {id= 16810, LoggedDate = DateTime.Now, OrderType="RB", OrderNo=106808, BranchCode="Jumeira", Status="Printed", PrinterName="printer A"},
new Reprintslist {id= 16811, LoggedDate = DateTime.Now, OrderType="RB", OrderNo=106808, BranchCode="Jumeira", Status="Printed", PrinterName="printer A"},
new Reprintslist {id= 16812, LoggedDate = DateTime.Now, OrderType="RB", OrderNo=106808, BranchCode="Jumeira", Status="Printed", PrinterName="printer A"},
new Reprintslist {id= 16813, LoggedDate = DateTime.Now, OrderType="RB", OrderNo=106808, BranchCode="Jumeira", Status="Printed", PrinterName="printer A"},
new Reprintslist {id= 16814, LoggedDate = DateTime.Now, OrderType="RB", OrderNo=106808, BranchCode="Jumeira", Status="Printed", PrinterName="printer A"},
};
}
public IActionResult OnPost(string[] selectedids)
{
return new JsonResult("success");
}
}
ReprintsIndex.cshtml page:
@page "/reprientsindex"
@model RazorWebApp.Pages.ReprintsIndexModel
@Html.AntiForgeryToken()
<button id="reprintdatabtn" style="margin-Left:10px;width:100px;" class="btn btn-primary">Reprint</button>
<table id="example" class="display">
<thead>
<tr>
<th><input id="chkHeader" type="checkbox"></th>
<th>EntredDatetime</th>
<th>OrderType</th>
<th>OrderNo</th>
<th>PrinterName</th>
<th>BranchCode</th>
<th>Status</th>
<th>Id</th>
</tr>
</thead>
<tbody>
@foreach (var reprint in Model.Reprintslist)
{
<tr>
<td><input id="chkSel" class="myCheckbox" type="checkbox"></td>
<td>@reprint.LoggedDate</td>
<td>@reprint.OrderType</td>
<td>@reprint.OrderNo</td>
<td>@reprint.PrinterName</td>
<td>@reprint.BranchCode</td>
<td>@reprint.Status</td>
<td id="idval">@reprint.id</td>
</tr>
}
</tbody>
</table>
@section Scripts{
<script>
$(function(){
$('#reprintdatabtn').click(function () {
var dataArr = [];
$('input:checked').each(function () {
dataArr.push($(this).closest("tr").find("#idval").html()); // insert rowid's to array
});
console.log(dataArr);
$.ajax({
type: "POST",
url: "/reprientsindex",
beforeSend: function (xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
data:{selectedids: dataArr},
success: function (response) {
alert(response);
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
});
});
</script>
}
The result as below:

If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion