views:

33

answers:

1

Hello EveryOne,

i m using asp.NET MVC 2 for my current project and i need to validate form fields both on client and server side. for that i started with DataAnnotations. Now, i figure out that i have to write buddy class for every model or i have to go to designer generated code and put my annotations there (not a good idea though). if someone can suggest me a solution that helps me avoid writing those buddy classes and get the same functionality.
Regards
Adeel

+1  A: 

You don't need to write a partial class. You could directly annotate your model properties. Checkout ScottGu's blog post.

Darin Dimitrov
Thanks Darin, But that's one of the two things i m trying to avoid. 1-writing code is designer generated classes. 2- Making hell a lot of buddy classes as number of my models would probably cross 100 easily. plz suggest some alternate solution where i could avoid these two conditions
Muhammad Adeel Zahid
You may take a look at the FluentValidation library (http://fluentvalidation.codeplex.com/). It allows you to externalize your validation logic from the models and express it using fluent interfaces. It also has great integration with ASP.NET MVC http://www.jeremyskinner.co.uk/2010/02/06/fluentvalidation-1-2-beta-2-and-mvc2-rc2/
Darin Dimitrov