All I want to know is the proper syntax for the Html.CheckBoxFor HTML helper in ASP.NET MVC.
What I'm trying to accomplish is for the check-box to be initially checked with an ID value so I can reference it in the Controller to see if it's still checked or not.
Would below be the proper syntax?
@foreach (var item in Model.Templates)
{
<td>
@Html.CheckBoxFor(model => true, item.TemplateId)
@Html.LabelFor(model => item.TemplateName)
</td>
}
If you click on the checkbox or the bold label it will check/uncheck the checkbox
itempart of your model or what?CheckBoxFor()(andCheckBox()) method is to bind to aboolproperty. SinceTemplateIddoes not appear to bebool, then do not useCheckBoxFor()- just generate the html manually, or to do it the mvc way - refer this answer