Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I working on razor page with .NET core 7 . my mainly issue How to pass unchecked checkboxes

from html page to page model on post method ?

so If I have group of checkboxes not checked so I need to pass it to page model as List on post method when submit form

so user click submit button then on post method fire then it will collect check boxes not checked values 1 2 3

view model used

What I have tried:

public class UserAccessViewModel
        {
            public int UserId { get; set; }

            public UserAccess userAccess { get; set; }
            public int[] checks { get; set; }
        }
on page.cshtml

@Html.AntiForgeryToken()
    <form method="post">
        <button id="FillCheckBox" type="submit" class="col-sm-1 btn btn-primary">Submit</button>
        <button id="UpdateCheckBox" type="submit" class="col-sm-1 btn btn-primary">Update</button>
        <div class="form-group row">
            <label for="user-id" class="col-sm-1 col-form-label" style="font-size:15px;font-family: 'Open Sans', sans-serif;font-weight: bold;">User ID</label>
            <div class="col-sm-3">
            <input id="useraccess-id" name="UserAccessViewModel.UserId" asp-for="UserAccess.UserId" type="text" class="form-control" style=" margin-left:10px;font-size:15px;font-family: 'Open Sans' , sans-serif;font-weight: bold;" />
            </div>
        </div>
    <input id="StockTake" name="UserAccessViewModel.checks" type="checkbox" asp-for="UserAccess.MODULECODE" value="1">
        <label for="lblStockTake">Stock Take</label>
    <input id="ShelfLabelPrint" name="UserAccessViewModel.checks" type="checkbox" asp-for="UserAccess.MODULECODE" value="2">
        <label for="lblShelfLabel">Shelf Label Print</label>

    <input id="Transfer" name="UserAccessViewModel.checks" type="checkbox" asp-for="UserAccess.MODULECODE" value="3">
        <label for="lblTransfer" style="margin-right:5px;">Transfer</label>

        
        <div class="form-group row">
                    
        
    </form>
on pagemodel .cshtml.cs

public async Task OnPost(UserAccessViewModel UserAccessViewModel)
{
   //How to pass checkboxes not checked to razor page
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900