.Net Core 3.0 MVC 视图。需要申请 - 以下模型的客户端验证。
尝试如下:
型号:人
public class Person {
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public int Age { get; set; }
}
验证规则:
public class PersonValidator : AbstractValidator<Person> {
public PersonValidator() {
RuleFor(x => x.Id).NotNull().NotEmpty();
RuleFor(x => x.Name).Length(0, 10);
RuleFor(x => x.Email).EmailAddress();
RuleFor(x => x.Age).InclusiveBetween(18, 60);
}
}
遵循文档,它显示“验证器”属性,但我在命名空间中找不到。