mrpmorris / blazor-university

Accompanying source code for blazor-university.com
https://blazor-university.com
MIT License
191 stars 75 forks source link

Remove usage of `async void` #10

Open mrpmorris opened 4 years ago

sven5 commented 4 years ago

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);
mrpmorris commented 4 years ago

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.