I’d like to have a reusable validator that I can use on a group of checkbox fields that will let me specify a minimum number to be selected and maximum number that can be selected. I’m not sure exactly how to create both the server side check and the client side validation to hook into the jQuery validate framework using unobtrusive javascript.
This question seems to be a good start on the client side adapter, but how do you tie it all together to validate it on the server?
Here’s how you could start at least for server side validation. Here’s a very nice article that illustrates multiple concepts.
Validation attribute:
Model:
Controller:
View (~/Views/Home/Index.cshtml):
Editor template (
~/Views/Home/EditorTemplates/bool.cshtml):