I working on asp.net core MVC razor page . I face issue I can't get checkbox checked or not on page model razor page .
so which checkbox have checked or not checked this is exactly I need to get on page model MVC.
so if checkboxes StockTake and ShelfLabelPrint checked so I will get value 1 and 2 is true on page model .
checkbox Transfer not checked so it will get value 3 status false .
public class AddUserAccessModel : PageModel
{
[BindProperty]
public UC.ADC.Core.Entities.SQL.UserAccess UserAccess { get; set; }
public async Task OnPost(UC.ADC.Core.Entities.SQL.UserAccess useraccess)
{
string[] checkedModuleCodes = Request.Form["checks"];
// How to recognize which check box have checked or not here
}
}
ON AddUserAccess.cshtml Razor view
@Html.AntiForgeryToken()
expectation result I need as below

Tuhin PaulPosted May 13, 2023, 2:14 AM
To recognize which checkbox have checked or not
This code will first get the value of the "checks" input field from the request. If the value is not null, it will then iterate through the values and set the corresponding value of the UserAccess.MODULECODE property. For example, if the user checks the "StockTake" and "ShelfLabelPrint" checkboxes, the UserAccess.MODULECODE property will be set to 1 and 2, respectively.
Rajkiran SwainPosted May 12, 2023, 2:44 PM
Check if you have declared and initialized the variables and objects correctly.
Ensure that you have included all the necessary libraries or packages that are required for your code to work.
Verify that the values you are passing to the objects are valid and not null.
Check for any typos or syntax errors in your code.
Debug your code to locate the exact line where the error is occurring.
If the error persists, try searching online for similar issues and possible solutions.
ahmed salahPosted May 12, 2023, 2:21 PM
i get error can't set object reference to null
Rajkiran SwainPosted May 11, 2023, 2:19 PM