I'm assuming that you want the label to tick the checkbox when you click on it.
In this case, the for
attribute of the HTML <label>
field must point to the ID of the relevant input element.
If you're using a model, @Html.CheckBoxFor
will generate a checkbox without an ID, so you will need to add an ID to the checkbox, then point your label to the same ID. The easiest way is to replicate the checkbox's name into its ID field using the @Html.NameFor
helper method. Here's an example:
@Html.CheckBoxFor(x => x.Active, new {id=Html.NameFor(x => x.Active)})
<label for="@Html.NameFor(x => x.Active)">Active</label>
Generated HTML (without validation attributes):
<input id="[0].Active" name="[0].Active" type="checkbox" value="true" />
<input name="[0].Active" type="hidden" value="false" />
<label for="[0].Active">Active</label>