blazor-university icon indicating copy to clipboard operation
blazor-university copied to clipboard

Remove usage of `async void`

Open mrpmorris opened this issue 6 years ago • 2 comments

mrpmorris avatar Jan 28 '20 21:01 mrpmorris

I was struggling to get async validation working.

RuleFor(x => x.FolderPath).MustAsync(ValidateFolderPath).WithMessage(o => "Invalid path.");

It's been working when changing the field's value but not when submitting the form.

The key is to change the code ValidationRequested event to run not async.

It's a little weird as the solution is to use sync Validate method of FluentValidation:

            // Tell FluentValidation to validate the object
            ValidationResult result = Validator.Validate(EditContext.Model);

sven5 avatar Apr 23 '20 18:04 sven5

It's tricky in validation because none of the Blazor EditContext stuff is async, which is partly why I haven't started to tackle this yet.

mrpmorris avatar Apr 23 '20 19:04 mrpmorris