I have a strongly typed partial view CheckBox.ascx
that renders a checkbox. This is used by another partial view that renders a list of checkboxes using CheckBox.ascx
.
I am having problems figuring out how to use the Html.Label
helper method to get labels working correctly, i.e. setting the label
for
property to be the id
of the related checkbox.
My view markup for the checkbox looks like this: (I'm using non-sequential list binding as described under Non-Sequential Indices)
<%= Html.CheckBox(string.Format("checkBoxes[{0}].Checked", Model.Id), Model.Checked)%>
The complexity here is that my checkbox ID will be mangled - [
, ]
, .
characters replaced with _
.
Can the Html.Label
helper method help me here?