just want to use one model to validate two times.the firstvalidator() will be used in one page ,and the sencond will be used in another page.
public class MyModel
{
public int Id { get; set; }
public string Name { get; set; }
public int Gender{ get; set; }
public string others{ get; set; }
}
public class FirstValidator : AbstractValidator<MyModel>
{
public FirstValidator ()
{
RuleFor(d => d.ID).NotNull().WithMessage("Required").Length(1, 20).WithMessage("xxx");
RuleFor(d => d.Name ).NotNull().WithMessage("Required").Length(1, 20).WithMessage("xxx");
}
}
public class SecondValidator : AbstractValidator<MyModel>
{
public SecondValidator ()
{
RuleFor(d => d.Gender).NotNull().WithMessage("Required").Length(1, 20).WithMessage("xxx");
RuleFor(d => d.others).NotNull().WithMessage("Required").Length(1, 20).WithMessage("xxx");
}
}