I have the following view model:
public class MyViewModel
{
public bool SingleFamily { get; set; }
public bool Condominium { get; set; }
public bool Townhouse { get; set; }
}
Below is my view:
<p>
@Html.Label("Property Type")
@Html.CheckBoxFor(m => m.SingleFamily)
<label>Single Family</label>
<br />
@Html.CheckBoxFor(m => m.Townhouse)
<label>Townhouse</label>
<br />
@Html.CheckBoxFor(m => m.Condominium)
<label>Condominium</label>
</p>
I would like to make sure that at least one checkbox is checked before the user submits the form. Also I would like to have the validation both on the server and the client side. What is the best way to achieve this?
I think you’ll need a custom validator
See http://devtrends.co.uk/blog/the-complete-guide-to-validation-in-asp.net-mvc-3-part-2 for a good example