Is there a way to selectively skip silverlight field validation when using wcf ria?

拟墨画扇 提交于 2019-12-11 02:06:48

问题


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)?


回答1:


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



来源:https://stackoverflow.com/questions/4125014/is-there-a-way-to-selectively-skip-silverlight-field-validation-when-using-wcf-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!