【发布时间】:2019-06-11 07:56:38
【问题描述】:
我为这个模型做了一个流利的验证类
public class OnlineCashierRequest
{
Guid InvoiceId { get; set; }
string ClientPhoneOrEmail { get; set; }
List<IOnlineCashierProduct> Products { get; set; }
}
public interface IOnlineCashierProduct
{
string Name { get; set; }
decimal Amount { get; set; }
int Count { get; set; }
}
我有一个 products 的规则,其中 Amount 等于 null。但是我怎样才能在消息行索引中写$"Amount is less zero for row {rowIndex}"
RuleForEach(t => t.Products)
.Must(x => x.Amount < 0)
.WithMessage(x => $"[{rowIndex}] Amount must be greater then zero\r\n");
【问题讨论】:
-
为什么需要行索引?
-
@chris 日志验证异常
-
在日志消息中使用
IOnlineCashierProduct的Name不是更好吗? -
@chris 不,也可能是产品名称为空的错误
标签: c# fluentvalidation