blazor-university
blazor-university copied to clipboard
Remove usage of `async void`
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);
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.