Home > Net >  FluentValidation ValidateAsync override never shows a failure
FluentValidation ValidateAsync override never shows a failure

Time:02-10

I am running a Blazor Server app and im using FluentValidation and PPioli.FluentValidation.Blazor packages and i'm not able to reliably get the results back to set other properties. When i override ValidateAsync, the returned results are always valid with no errors, even though the validation results are triggered in the UI.

public class FormValidator : AbstractValidator<FormModel>
    {
        public FormValidator()
        {
            RuleFor(V => V.Username)
                .NotEmpty().WithMessage("Username cannot be empty");

        }

        public override Task<ValidationResult> ValidateAsync(ValidationContext<LoginModel> context, CancellationToken cancellation = default)
        {
            var result = Task.FromResult(new ValidationResult());
            return base.ValidateAsync(context, cancellation);
        }

    }

result.Result.IsValid is ALWAYS true, even when validation is failing and showing in the UI.

result.Result.Errors.Count is ALWAYS 0, even when validation is failing and showing in the UI.

There is no indication in the results variable that any validation is failing, even though it clearly is failing

CodePudding user response:

  •  Tags:  
  • Related