Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass list of checkboxes not checked on page model razor page?

Status
Not open for further replies.

AhmedAzizBarbary

Programmer
May 13, 2023
2
0
0
EG
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

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

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

HTML:
@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

Code:
public async Task OnPost(UserAccessViewModel UserAccessViewModel)
{
   //How to pass checkboxes not checked to razor page
}
for more details what I need

pass unchecked checkboxes to razor page
unchecked_checkboxes_m8hp58.png
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top