Umair Ahmad

Umair Ahmad

  • NA
  • 32
  • 2.6k

Check All Checkbox in Razer MVC html table

May 12 2022 4:39 PM

I need to implement check all checkbox which will check and uncheck the checkboxes in rows.

<table id="instruments" class="table table-bordered table-striped table-condensed table-hover smart-form has-tickbox" style="width: 100%;">
    <thead>
        <tr>
            <th>
                <input type="checkbox"/>                                               
            </th>                                            
            <th data-class="expand" style="white-space: nowrap">@Model.SResource</th>
            <th data-hide="phone" style="white-space: nowrap">@Model.KResource</th>
            <th data-hide="phone" style="white-space: nowrap">@Model.LocationResource</th>
        </tr>
    </thead>
    <tbody>
        @for (int i = 0; i < Model.Instruments.Count; i++)
        {
            var values = Model.Instruments[i].Value.Split('~');
            var status = values.Length > 0 ? values[0] : "";
            var location = values.Length > 1 ? values[1] : "";

            <tr>
               <td>
                   <label class="checkbox">
                         @Html.CheckBoxFor(m => m.Instruments[i].Selected)
                         <i></i>
                    </label>
                </td>
                <td><label>@Model.Instruments[i].Text</label></td>
                <td><label>@status</label></td>
                <td><label>@location</label></td>
            </tr>
        }
    </tbody>
</table>

 


Answers (8)