I have a form that contains 9 input
of type checkbox
I need to validate that when sending the form at least one of them comes tickeado.
I have the following in my view
<div class="col-12 col-sm-6 col-md-3 li">
@Html.HiddenFor(m => m.MiCheckViewModel.Institutions[0].Value)
@Html.HiddenFor(m => m.MiCheckViewModel.Institutions[0].Text)
<label>
@Html.CheckBoxFor(m => m.MiCheckViewModel.Institutions[0].Selected)
<span class="title">@Model.MiCheckViewModel.Institutions[0].Text</span>
</label>
</div>
In total I have 9 fields in the same way.
In my model I have the following
public class Input
{
public Input()
{
this.MiSelectViewModel = new MiSelectViewModel();
this.MiCheckViewModel = new MiCheckViewModel();
}
public MiSelectViewModel MiSelectViewModel { get; set; }
public MiCheckViewModel MiCheckViewModel { get; set; }
}
public class MiSelectViewModel
{
public List<SelectListItem> Institutions { get; set; }
public List<int> SelectedInstitutions { get; set; }
}
public class MiCheckViewModel
{
public List<SelectListItem> Institutions { get; set; }
public List<int> SelectedInstitutions { get; set; }
}
How can I do this in the correct way, to be able to do the validation from the model of the fields that arrive from the view, using the data anottation of ASP.NET MVC?
The main problem is to avoid sending the form without ticking any checkbox.