流畅的验证.错误:不显眼的客户端验证规则中的验证类型名称必须是唯一的 [英] Fluent Validations. Error: Validation type names in unobtrusive client validation rules must be unique
问题描述
我得到了错误:
不显眼的验证类型名称客户端验证规则必须是独特的.以下验证类型被看到不止一次:需要.这看到以下验证类型不止一次:必填
Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required. The following validation type was seen more than once: required
我使用了服务器验证.一切正常.但现在我要使用客户端验证,但我遇到了这个问题.
I used server validation. And all worked fine. But now I`m stating to use client-side validation and I got this problem.
这是我的验证类代码:
public class TestViewDataValidation : BaseTestCreateViewDataValidation<BaseTestCreateViewData>
{
public TestViewDataValidation ()
{
this.RuleFor(x => x.Login).NotNull();
this.RuleFor(x => x.Login).NotEmpty();
this.RuleFor(x => x.Login).EmailAddress();
}
}
但是如果我留下一个验证器 - 一切正常.我应该怎么做才能对字段进行更多的验证.
But if I leave one validator - all works fine. What should I do to have more that one validation for field.
推荐答案
FluentValidation.NET
之所以称为 Fluent 是因为它提供了一个 流式接口,用于链接方法:
FluentValidation.NET
is called Fluent because it provides a fluent interface for chaining methods:
public TestViewDataValidation()
{
RuleFor(x => x.Login)
.NotNull()
.NotEmpty()
.EmailAddress();
}
备注:在这种情况下,NotNull
和 NotEmpty
规则的使用对我来说似乎是多余的.NotEmpty
应该足够了.
Remark: the usage of NotNull
and NotEmpty
rules seem reduntant to me in this case. NotEmpty
should be enough.
这篇关于流畅的验证.错误:不显眼的客户端验证规则中的验证类型名称必须是唯一的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!