I'm trying to implement a required validation on a group of checkboxes. Basically one of them needs to be checked and the number of checkboxes is dynamic. I'm not excactly confident in the code below, I'm starting to assume I might need to use Javascript. I think the code speaks best for itself.
HTML:
@for (var i = 0; i < Model.Sessions.Count(); i++ )
{
@Html.HiddenFor(it => it.Sessions[i].Id)
@Html.LabelFor(it => it.Sessions[i].Name, Model.Sessions[i].Name)
@Html.CheckBoxFor(it => it.Sessions[i].Checkbox)
}
@Html.ValidationMessageFor(model => model.Sessions)
C# (Viewmodel):
[NotNull]
[GlobalisedRequired]
public virtual List<CheckBoxModel> Sessions { get; set; }