You've asked this question many times. The community has explained the holes in your understanding and responded with several different approaches. These code samples range from JavaScript, tag helpers, using a hidden field, basic HTML, and basic C# logic. It would be easier to provide further assistance if you explained why the previous code samples did not work for you.
Unfortunately, your most recent code snippet has too many issues to guess how the logic is intended to function. My best guess...
The four checkboxes have values 3X, 2X, 1X, and X. Since the browser only submits a checked checkbox (name/value), all you have to do is check if the a corresponding bound property is null or empty. If the property is null then the checkbox was not checked.
@page
@model RazorPagesDemo.Pages.Forms.IndexModel
@{
ViewData["Title"] = "Basic HTML Forms";
}
<div class="col-md-8">
<form asp-page-handler="Insert">
<table class="table align-items-center table-flush">
<thead class="thead-dark">
<tr>
<th scope="col">Printers</th>
<th scope="col"><input type="checkbox" name="all" id="all" checked /></th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Tamayaz Point 3X (Gold)</th>
<td>
<input type="checkbox" name="Gold" value="3X" checked="@(!String.IsNullOrEmpty(Model.Gold))" />
</td>
</tr>
<tr>
<th scope="row">Tamayaz Point 2X (Silver)</th>
<td>
<input type="checkbox" name="Silver" value="2X" checked="@(!String.IsNullOrEmpty(Model.Silver))" />
</td>
</tr>
<tr>
<th scope="row">Tamayaz Point 1X (Green)</th>
<td>
<input type="checkbox" name="Green" value="1X" checked="@(!String.IsNullOrEmpty(Model.Green))" />
</td>
</tr>
<tr>
<th scope="row">Tamayaz Point X (Black)</th>
<td>
<input type="checkbox" name="Black" value="X" checked="@(!String.IsNullOrEmpty(Model.Black))" />
</td>
</tr>
</tbody>
</table>
<div>
<input type="submit" name="Insert" value="Insert" />
</div>
</form>
</div>
<div>
<div>Red Checked = @(!String.IsNullOrEmpty(Model.Gold)) Value = @Model.Gold</div>
<div>Green Checked = @(!String.IsNullOrEmpty(Model.Silver)) Value = @Model.Silver</div>
<div>Blue Checked = @(!String.IsNullOrEmpty(Model.Green)) Value = @Model.Green</div>
<div>Black Checked = @(!String.IsNullOrEmpty(Model.Black)) Value = @Model.Black</div>
@if (Model.Values != null)
{
<div>
Values = @(String.Join(", ", Model.Values))
</div>
}
</div>
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace RazorPagesDemo.Pages.Forms
{
public class IndexModel : PageModel
{
public void OnGet()
{
}
public void OnPostInsert()
{
if(!String.IsNullOrEmpty(Gold))
{
//Gold is selected
Values.Add(Gold);
}
if (!String.IsNullOrEmpty(Silver))
{
//Silver is selected
Values.Add(Silver);
}
if (!String.IsNullOrEmpty(Green))
{
//Green is selected
Values.Add(Green);
}
if (!String.IsNullOrEmpty(Black))
{
//Black is selected
Values.Add(Black);
}
}
[BindProperty]
public string? Gold { get; set; }
[BindProperty]
public string? Silver { get; set; }
[BindProperty]
public string? Green { get; set; }
[BindProperty]
public string? Black { get; set; }
public List<string> Values { get; set; } = new List<string>();
}
}