在POCO和MVC上使用数据注释进行远程验证 [英] Using Data Annotations on POCO's with MVC for Remote Validation
问题描述
我正在开发ASP.NET MVC应用程序,并且一直在研究在服务层中定义的POCO上使用数据注释.只要我对System.ComponentModel& System.ComponentModel.DataAnnotations没问题,我喜欢它的地方是它允许我在Win Forms应用程序中重用服务层.
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
但是,要在这种情况下使用数据注释,我需要引用System.Web.MVC, System.Web和System.Web.Routing.这引入了对Web DLL的依赖性, 在某种程度上限制了我.
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.
任何人都可以推荐一种干净的方法来使用不与ASP.NET MVC结合使用的数据注释来实现远程数据验证,或者可以提出更好的替代方法.
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.
感谢您的帮助!
推荐答案
最后,我避免了将DataAnnotations放在POCO上,而是将它们放在ViewModels上,并使用AutoMapper在ViewModel和POCO之间进行映射,从而解决了此问题. (这为我节省了一些乏味的映射时间).在Automapper上有一个很棒的视频, http://perseus.franklins.net/dnrtvplayer /player.aspx?ShowNum=0155
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
这篇关于在POCO和MVC上使用数据注释进行远程验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!