Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Data Annotations on POCO's with MVC for Remote Validation

I am developing an ASP.NET MVC app and I've been looking into using Data Annotations on my POCO's which are defined in my Service Layer. As long as I have a reference to System.ComponentModel & System.ComponentModel.DataAnnotations this is no problem and what I like about this is that it allows me to reuse my Service Layer in a Win Forms app.

I'm now looking to do some Remote Validation using Data Annotations and have taken a look at this article: http://msdn.microsoft.com/en-us/library/ff398048(VS.100).aspx

However, to use the Data Annotations in this context I need to reference System.Web.MVC, System.Web and System.Web.Routing. This introduces a dependency on the Web DLL's, which limits me somewhat.

Can anyone recommend a good clean way to implement Remote Data Validation using Data Annotations that isn't coupled with ASP.NET MVC or maybe suggest a better alternative.

Thanks for the help !

like image 756
Click Ahead Avatar asked Nov 06 '22 13:11

Click Ahead


1 Answers

I resolved this in the end by backing away from putting DataAnnotations on my POCO's and instead I put them on my ViewModels and use AutoMapper to Map between my ViewModel and POCO (which saves me some time doing tedious mapping). There's a great video on Automapper here http://perseus.franklins.net/dnrtvplayer/player.aspx?ShowNum=0155

like image 142
Click Ahead Avatar answered Nov 29 '22 20:11

Click Ahead