这是我的验证类之一:
public class StocksValidator : AbstractValidator<Stocks>
{
public StocksValidator()
{
RuleFor(x => x.SellerId).GreaterThan(1).WithMessage("SellerId should be greater than 1")
.LessThan(100).WithMessage("SellerId should be less than 100");
RuleFor(x => x.SellerType).GreaterThan(101).WithMessage("SellerType should be greater than 101")
.LessThan(200).WithMessage("SellerType should be less than 200");
RuleFor(x => x.SourceId).GreaterThan(201).WithMessage("SourceId should be greater than 201")
.LessThan(300).WithMessage("SourceId should be less than 300");
}
}
Run Code Online (Sandbox Code Playgroud)
我知道这些消息,例如{field}应该少于{x}应该位于公共位置,而不是这里。但是我不知道如何集中他们?
一种方法是使用所有这些常量字符串创建新的c#文件。这很简单。
在Web API中使用本地化和流畅的验证。这有什么好处。我在哪里可以找到好的教程?