ahmedaziz
Well-known member
- Joined
- Feb 22, 2023
- Messages
- 55
- Programming Experience
- 1-3
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
on page.cshtml
on pagemodel .cshtml.cs
for more details what I need
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
UserAccessViewModel:
public class UserAccessViewModel
{
public int UserId { get; set; }
public UserAccess userAccess { get; set; }
public int[] checks { get; set; }
}
on page.cshtml
page model csharp:
@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
on post method pass uncheck checkbox:
public async Task OnPost(UserAccessViewModel UserAccessViewModel)
{
//How to pass checkboxes not checked to razor page
}
for more details what I need