i followed all of these steps in this tutorial:
Created a validator class
public class ProjectValidator : AbstractValidator<ProjectViewModel>
{
public ProjectValidator()
{
//RuleFor(h => h.Milestone).NotEmpty().WithName("Milestone");
RuleFor(h => h.Applications).NotNull().WithName("Application");
RuleFor(h => h.InitiativeName).NotNull().WithName("Business Aligned Priority");
RuleFor(h => h.BusinessDriverId).NotNull().WithName("Business Driver");
RuleFor(h => h.FundingTypeId).NotNull().WithName("Funding Type");
RuleFor(h => h.Description).NotEmpty().WithName("Description");
RuleFor(h => h.Name).NotEmpty().WithName("Project Name");
RuleFor(h => h.Sponsors).NotNull().WithName("Sponsors");
}
}
Put an attribute on my DTO to specific this validtor
[Validator(typeof(ProjectValidator))]
public class ProjectViewModel
{
}
but after a form post when i go to check the ModelState errors list, the errors i see are coming from the asp.net-mvc default validation.
public ActionResult UpdateMe(ProjectViewModel entity)
{
Project existingProject = this.Repository.Fetch<Project>(entity.Id);
UpdateProperties(entity, existingProject);
var allErrors = ModelState.Values.SelectMany(v => v.Errors);
if (allErrors.Count() > 0)
{
any suggestions on why its not picking up the fluent. validator ?? I have added an image below of what i see on the gui
if i call the validator directly in code it works just fine:
ProjectValidator validator = new ProjectValidator();
ValidationResult result = validator.Validate(entity);