Question

I'm trying to decide what validation approach to take for a new ASP.NET MVC project. (And wow there are plenty of options!)

The project uses NHibernate, so the first thing I considered was the NHibernate Validator (Because of tight integration with NHibernate). However, as far as I can see there are only a couple of benefits to this tight integration:

1) DB Schemas generated by NHibernate will include details of validation (e.g. column lengths will be set to max value allowed in validation). (This is not really of interest to me though, as I generate schemas manually.)

2) NHibernate will throw an exception if you try to save data that doesn't meet the validation specs. (This seems fairly redundant to me, since the data presumably will already be validated by whatever mechanism you choose before saving anyway)

If there are more benefits to NHibernate Validator please let me know!

Other libraries which I've been reading a little about include:

  • MS DataAnnotations
  • Castle Validator
  • Something else?

I've also been thinking about using xVal to provide client side validation from the same set of rules. However, I hear that ASP.NET MVC v2 will include something similar to xVal (integration with jquery) out of the box? Will this new included functionality render some of the others redundant?

So, I'm basically asking for people's advice on which direction to take here. I don't want to implement a particular scheme, only to have to rip it out when another one becomes the dominant tech.

What has worked for you? Which option do you think has/will have the edge?

Thanks!

Was it helpful?

Solution

I have been using FluentValidation along with jQuery validation plugin and still cannot find a situation they cannot handle.

OTHER TIPS

I like xVal.

You can implement very easily client and server validation with it. Also there is support for column (property) validation on entities that you would like to use.

DataAnnotations implemented by buddy classes and JQuery client validation

Make sure you're using MVC Preview 2

You might be interested in this delegate approach. I was because i didn't like the xVal idea (the solution im currently going with) and the fact that it didn't seem to cater for complex validation cases that crossed multiple properties of the same or even different class structures.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top