1

I've found the model annotations very useful for the validation in MVC but can't seem to get it working for a checkbox. I am using MVC 3 with razor and c#.

Thanks

Funky
  • 12,890
  • 35
  • 106
  • 161
  • What are you trying to validate? That it is checked? Are you suggesting that a false value for your property is not a valid value? Is this a checkbox for a user to "check" in order to go to a next step like accepting a terms of service? – CD Smith Apr 25 '12 at 15:13
  • 1
    See: http://stackoverflow.com/questions/2766952/how-would-you-validate-a-checkbox-in-asp-net-mvc-2 – Faust Apr 25 '12 at 15:21

1 Answers1

0

Last time I heard this question, the customer wanted to verify whether the question had been answered or not. This is not possible with a checkbox, and can only be done by using a pair of radio buttons for yes and no and defaulting both to unchecked. Then when submitted, if neither button is checked, validation fails.

KennyZ
  • 907
  • 5
  • 11