1

MVC 2 comes with 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 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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks Darin, could u plz refer some example or preferably a sample project to get started with FluentValidations
Take a look at the second link. It provides all that's necessary to get started. The documentation is also quite extensive.
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 side regards Adeel
In the link I provided it states that for client validation: at the moment, only the NotNull, NotEmpty, RegularExpression and Length validators are supported.
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.