ahmed salah

ahmed salah

  • 1.2k
  • 547
  • 64.5k

How to get checkboxes checked or not on razor asp.net ?

Jun 27 2023 1:02 PM

I have two checkbox razor html .i face issue how to detect which checkbox checked or not on page model 

<div class="col-md-8">
    <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" id="cbRed"  name="cbprinter">
                </td>
            </tr>
            <tr>
                <th scope="row">Tamayaz Point 2X (Silver)</th>
                <td>
                    <input type="checkbox"  id="cbBlue" name="cbprinter">
                </td>
            </tr>
            <tr>
                <th scope="row">Tamayaz Point 1X (Green)</th>
                <td>
                    <input type="checkbox"  id="cbGreen" name="cbprinter">
                </td>
            </tr>
            <tr>
                <th scope="row">Tamayaz Point X (Black)</th>
                <td>
                    <input type="checkbox"  id="cbBlack" name="cbprinter">
                </td>
            </tr>
            <tr>
                <th scope="row">Normal (Black & White)</th>
                <td>
                    <input type="checkbox"  id="cbNormal" name="cbprinter">
                </td>
            </tr>
        </tbody>
    </table>
</div>

so which checkboxes of these have checked or not on page model

I need to write csharp code detect which checkboxes checked or not on page model

public class LabelPrintingModel : PageModel
{
       
public LabelPrintingModel()
{

}
Public void OnPostInsert()
{
//which checkbox on razor html checked true 
}
}

Answers (4)