问题描述
我有一个金额对象。 我想通过流利的验证检查数量是否在1到100之间。
RuleFor(x=>x.TotalAmount)
.NotEmpty()
.WithLocalizedMessage(() => AccountResources.Validation_MissingAmountValue)
.InclusiveBetween(1,999999999)
.WithLocalizedMessage(() => AccountResources.Validation_InvalidamountValue);
inclusiveBetween不起作用,因为数量是字符串类型。
解决方法
使用Transform()方法并解析该值以键入所需的类型。 这是您可以检查的链接。