Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Possible to use same model validate two times?

$
0
0
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");
    }
}

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>