开发者

How to return warnings from server side to silverlight

开发者 https://www.devze.com 2023-01-31 06:08 出处:网络
We have a business case that need to return both validation errors and warings fro开发者_JAVA技巧m server side and display on silverlight.

We have a business case that need to return both validation errors and warings fro开发者_JAVA技巧m server side and display on silverlight. I see the silverlight is using System.ComponentModel.DataAnnotations.ValidationResult to process errors. It does not contain and fields for "warnings".

I am wondering if anybody has a good idea to handle this problem. Thanks.


I think ValidationResult is used by ValidationException which is thrown by the subclasses of ValidationAttribute. Normally this mecanism is used with blocking validation errors because throwing to exception stops execution of the code. If it happens in your service, the exception can be sent to the client and processessed, but this is not always a wanted scenario.

You could extend this model (those classes ValidationAttribute, its subclasses, ValidationException are not sealed) to add a warning flag but then you'd have to trap the exception to continue the processing and rethrow in case of a warning.

Another alternative is to add business logic validation errors and warnings to your response to the client. I like this approach because you can then include whatever info you want the way you want/need it.

0

精彩评论

暂无评论...
验证码 换一张
取 消