I working on razor page using .net core 7 . i face issue i can't pass check boxes uncheck to on post function on page model
I have group of checkboxes have checked false with another meaning not checked
so How to get unchecked checkboxes as list of values
my code details
Code
@Html.AntiForgeryToken()
Submit
User ID
Stock Take
Shelf Label Print
Transferon pagemodel
Code
public async Task OnPost(UserAccessViewModel UserAccessViewModel)
{
}view model used
C#
public class UserAccessViewModel
{
public int UserId { get; set; }
public UserAccess userAccess { get; set; }
public int[] checks { get; set; }
}
to see expected result i need as below


Deepak RawatRank #646 · 3.7K reputationPosted May 13, 2023, 2:51 PM EDT
Hi I don't know more about your problem but you can find solution here:
https://www.learnrazorpages.com/razor-pages/forms/checkboxes
ahmed salahRank #2,240 · 628 reputationPosted May 13, 2023, 3:10 PM EDT
can you please help me answering by post code here please
Deepak RawatRank #646 · 3.7K reputationPosted May 13, 2023, 3:15 PM EDT
.cshtmlfile, define a form with checkboxes inside a loop that iterates over a list of items:the corresponding
.cshtml.csfile, handle the form submission in theOnPostmethod:public IActionResult OnPost() { // Retrieve the selected checkbox values string[] selectedItems = Request.Form["selectedItems"]; // Iterate over all items and check which ones were not selected foreach (var item in Model.Items) { bool isSelected = selectedItems.Contains(item.Id); if (!isSelected) { // Do something with the unchecked item // For example, add it to a list or perform any desired logic // item is not selected } } // Redirect or return a view return RedirectToPage("Index"); }In the code snippet above,
Model.Itemsrepresents the list of items you want to display checkboxes for. The checkbox values are submitted in theselectedItemsarray. By comparing the submitted values with the original list, you can determine which checkboxes were left unchecked. In the example, the unchecked items are processed inside theif (!isSelected)block, but you can modify it according to your needs.ahmed salahRank #2,240 · 628 reputationPosted May 13, 2023, 4:44 PM EDT
my case is static checkbox so can you help me display unchecked checkbox as lsit of 1,2,3
because i can't get checkbox unchecked on post method