0

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][email protected][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.

6
  • Why do you manually set the checked attribute value? The checkbox state is defined by result of expression, that you passed as first argument of the helper method Commented Apr 11, 2018 at 13:03
  • @Alexander It is some fake data that I have in my controller to see whether its pulling the data from the model. I have removed all of that and gone back to the basics and it renders the checkbox input. Is there a way that I can lock it? Commented Apr 11, 2018 at 15:09
  • Do you mean disabled attribute? Commented Apr 11, 2018 at 15:15
  • Or do you want to checkbox will be checked by default? Commented Apr 11, 2018 at 15:18
  • @Alexander the disabled option is okay, but I would like it so that you cant click the checkboxes. So they are locked. Commented Apr 12, 2018 at 7:28

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.