[英]ServiceStack validation for multiple properties
How do I write the validation rule if I want to check if at least one of the properties in the request DTO is not empty? 如果要检查请求DTO中的至少一个属性是否不为空,如何编写验证规则?
I can do it individually, but I can't seem to figure out how to combine multiple to do something like - check if at least one of FirstName, LastName and CompanyName has a value. 我可以单独执行此操作,但似乎无法弄清楚如何组合多个以执行类似操作-检查FirstName,LastName和CompanyName中至少有一个是否具有值。
This is a Fluent Validation question, you can use When()
to selectively apply the rule, eg: 这是一个流利的验证问题,您可以使用When()
选择性地应用规则,例如:
RuleFor(x => x.FirstName)
.NotEmpty()
.When(x => (x.LastName ?? x.CompanyName).IsNullOrEmpty());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.