简体   繁体   中英

Make a Checkbox none clickable ASP.NET MVC5

I have a table which renders some data from the Model and Controller. I have the table working, however, is there a way that I can stop the checkboxes in the table being clicked.

My code is:

<tbody>
                @for(var i = 0; i < Model.Writers.Count(); i++)
                {
                <tr data-id="@Model.Writers[i].WriterId"
                    data-name="@Model.Writers[i].FirstName@Model.Writers[i].LastName"
                    data-membership="@Model.Writers[i].Membership"
                    data-capipinumber="@Model.Writers[i].CaeIpiNumber"
                    data-share="@Model.Writers[i].Share"
                    date-righttocollect="@Model.Writers[i].RightToCollect">

                    <td>@Model.Writers[i].FirstName @Model.Writers[i].LastName</td>
                    <td class="hidden-xs hidden-sm">@Model.Writers[i].Membership</td>
                    <td class="hidden-xs">@Model.Writers[i].CaeIpiNumber</td>
                    <td>@Model.Writers[i].Share</td>
                    <td class="hidden-xs hidden-sm text-center">
                    @Html.CheckBoxFor(m => m.Writers[i].RightToCollect, new { @class = "control-label" })
                    </td>
                </tr>
                tableRowIndex++;
}
            </tbody>

I am just a little unsure whether it is possible to make the checkboxes no clickable, so they are locked in a way.

In the end, I used the HTML disabled attribute like so:

@Html.CheckBoxFor(m => m.Writers[i].RightToCollect, new { @disabled = "disabled" })

It disabled all the checked and unchecked checkboxes, so you can't click on them, which is exactly what I was looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM