views:

1266

answers:

9

I'm thinking of two options right now for model-base validation for an ASP.net project I'm starting:

xVal (Steve Sanderson's project) and the Enterprise module that Stephen Walther uses on this page

I don't really know enough to talk about the preferences as I haven't used either of them yet. Any ideas?

Update Using LinqToSql for ORM right now, but am open to changes.

A: 

Are you using an ORM? If so, which one are you using? I've had a lot of luck, when using Castle ActiveRecord, simply sticking with their default model-level validation. If you're not using that, though, this is probably not too helpful. :-)

Ryan Duffield
+1  A: 

FluentValidation is nice. NHibernate also has built in model validation. Then you need something like Scott Guthrie's technique for binding errors to the UI.

liammclennan
+1  A: 

I've been using xVal to and i have integrated it into the IDataErrorInfo interface introduced into MVC RC1. I like it.

Here is a post I wrote which explains a few things.

http://schotime.net/blog/index.php/2009/03/05/validation-with-aspnet-mvc-xval-idataerrorinfo/

Hope this helps.

Schotime
+1  A: 

Shamelessly promote my validation library. Built for jQuery validate & Enterprise Library and work out of the box for just that. That said, functionality and code are simple enough to modify/extend if you want.

Buu Nguyen
+5  A: 

One difference I see in reviewing the two is that Stephen Walther's blog post describes a library which does only validation in the Web server, where as xVal works with jQuery validators to do in-browser validation, as well. This feature, incidentally, is almost completely automatic.

Craig Stuntz
+1  A: 

You could also check out this new technique on LosTechies http://www.lostechies.com/blogs/hex/archive/2009/06/10/opinionated-input-builders-for-asp-net-mvc-part-5-the-required-input.aspx I like the fact that you inputs are setup globaly which is really DRY. Also you could just skip the client side validation and do an jquery ajax submit form to the server, which performs validation model and business logic all in one place, which is also DRY :) Also it means you will get the product out the door quicker and you can add client side validation later as a bonus or to progressively enhance the forms.

Jake Scott
+1  A: 

Another vote for xVal. It's real sweet. I like using Buddy Classes and DataAnnotations to do the validation lifting. Outside of making things work with Linq2Sql as you cannot add attributes to your fields, buddy classes give one a bit of flexibility to have multiple models share the same validation info. Comes in real handy for those ModelEditData classes that seem to always become neccessary.

Wyatt Barnett
A: 

Yes I'm using Nhibernate