×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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 --> c#

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

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

CODE --> 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 --> c#

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close