Validator.TryValidateObject Not Validating RangeAttribute

*爱你&永不变心* 提交于 2019-11-30 05:36:27

Ah so it would seem I need to specify validateAllProperties = true

Validator.TryValidateObject(question, ctx, results, true);

Incidentally what was throwing me off was the fact I had an abstract base class with another property in it and without validateAllProperties the Validator will stop on the first error of ALL superclasses too. So you will get a validation error for each superclass (in my case 2)

Validator.TryValidatorObject(instance, validationContext, validationResults) calls Validator.TryValidateObject(instance, validationContext, validationResults, validateAllProperties) with validateAllProperties = false.

When validateAllProperties is false, only the RequiredAttribute will be validated.

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