views:

35

answers:

1

Hello,

mvc 2 comes wit built-in support of Model validation but how do i do "input validation". for example i have an interface of creating memo where i have populated the view with dynamic checkboxes corresponding to employees. The validation is straight forward i.e do not submit if no checkbox is selected. i wonder if there is a way of doing such things in DataAnnotations. i have searched the internet and found that people have written hell a lot of code to validate password and confirm password validation just for the sake of doing it the nicer way. My question is if there is a nicer way for my problem or should i just count number of checkboxes in my controller action and return error if no checkbox is selected

regards
adeel

+1  A: 

I would recommend you looking at the FluentValidation library which integrates nicely with ASP.NET MVC.

Darin Dimitrov
Thanks Darin,could u plz refer some example or preferably a sample project to get started with FluentValidations
Muhammad Adeel Zahid
Take a look at the second link. It provides all that's necessary to get started. The documentation is also quite extensive.
Darin Dimitrov
Thanks Darin, i have tried using Fluent validation and it works great on server side but never shows up on client side using Microsoft validation. i searched about that and found that even xval provide limited support for fluent validation on client side. the rule i want to apply is RuleFor(x => x.Contact).EmailAddress().When(x => x.ContactType.Equals("Email"));which works on server sideregardsAdeel
Muhammad Adeel Zahid
In the link I provided it states that for client validation: `at the moment, only the NotNull, NotEmpty, RegularExpression and Length validators are supported.`
Darin Dimitrov
Thanks Darin,yes it does state that client side validation is supported for some trivial scenarios but what i want is to get complex validations on client side too. is there a way i can hook fluent validations json using jquery (preferably) or by some other js library. regards
Muhammad Adeel Zahid