有没有办法在使用wcf ria时选择性地跳过silverlight字段验证? [英] Is there a way to selectively skip silverlight field validation when using wcf ria?

查看:157
本文介绍了有没有办法在使用wcf ria时选择性地跳过silverlight字段验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个(可能是常见的)情况,我想在我的silverlight应用程序(SL4,WCF RIA,EF4,Linq-to-Entities)中添加一个新实体和编辑现有实体,重用同一个类。添加新的时候,我希望我的自定义验证器检查唯一性,如果不是唯一的,则会失败。但是,编辑时,我不希望同样的验证器阻止编辑。有没有办法暂时关闭单个字段的验证(理想情况下是通过验证类型,以便其他验证器仍然可以在同一个字段上运行)?

解决方案

您可能需要在此处查看ValidationContext容量。您可以具有根据实体或任何其他要提供的属性进行决策的验证属性。



查看我提供ValidationContext和使用ValidationContext的博文:



http:/ /jeffhandley.com/archive/2010/10/25/RiaServicesValidationContext.aspx



http://jeffhandley.com/archive/2010/10/25/CrossEntityValidation.aspx



希望这有帮助,



Jeff


I have a (likely common) case where I would like to reuse the same class for both adding a new entity and editing an existing entity in my silverlight app (SL4, WCF RIA, EF4, Linq-to-Entities). When adding a new one, I would like my custom validator to check for uniqueness and fail if it's not unique. However, when editing, I don't want that same validator to prevent edits. Is there a way to temporarily turn off validation for a single field (ideally by validation type so that the other validators can still run on that same field)?

解决方案

You might want to check out the ValidationContext capabilties here. You can have validation attributes that make decisions based on properties on the entity, or any other state you want to provide.

Check out my blog posts on Providing ValidationContext and Using ValidationContext:

http://jeffhandley.com/archive/2010/10/25/RiaServicesValidationContext.aspx

http://jeffhandley.com/archive/2010/10/25/CrossEntityValidation.aspx

Hope this helps,

Jeff

这篇关于有没有办法在使用wcf ria时选择性地跳过silverlight字段验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆