Data annotations – customize data annotations using RIA services

If you use riaservices with custom validatorattributes, this is one or more warning words

This is senario. I am creating a custom dataannotation, which will verify the properties according to whether a series of other properties are set, such as; If PROP1 is 100, prop2, prop3 or prop4 cannot be 0, one of them must be set I also use the RIA service, so I created validatorattribute shared. CS file After writing all the tests for the helper cannotbezeroif class, I started adding attributes to the model class When things start to get very wrong, RIA services starts throwing a nullreferenceexception during CodeGen@ H_ 301_ 3@

Createriaclientfilestask – > NullReferenceException@H_301_3 @

It turns out that I'm using the validator's constructor to pass values to classes Everything was fixed by switching to using objectinitialization syntax@ H_ 301_ 3@

When dealing with RIA services and custom dataannotation validator, the answer seems to use objectinitializer syntax@ H_ 301_ 3@

Solution

The answer seems to be to use objectinitializer syntax when dealing with RIA services and custom dataannotation validators (which is easier than I thought!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>