You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I am trying to add custom validation error message AFTER the form has been submitted successfully for an existing field.
In Razor Pages I can do something like: ModelState.AddModelError("Form.Field", "Something happened!"); which allows the error message to be displayed when the page is returned. (Bonus Point doing it like this because it allows the field CSS to also be displayed as errored field)
I can't find a way to do this in Blazor.
Describe the solution you'd like
I need a way to do ModelState.AddModelError in Blazor. Is it possible to expose ModelState altogether in Blazor?
Additional context
We apparently cannot simply use custom validation annotation because the validation may be async. (aspnet/Mvc#7791 required for this behavior)
Related to issue, might qualify as separate issue:
protectedoverride ValidationResult IsValid(objectvalue,ValidationContextvalidationContext){varservice=(IExternalService) validationContext
.GetService(typeof(IExternalService));// use service}
In Blazor, GetService returns NULL!
EDIT 2: Solved the issue, although with a different approach:
Is your feature request related to a problem? Please describe.
I am trying to add custom validation error message AFTER the form has been submitted successfully for an existing field.
In Razor Pages I can do something like:
ModelState.AddModelError("Form.Field", "Something happened!");
which allows the error message to be displayed when the page is returned. (Bonus Point doing it like this because it allows the field CSS to also be displayed as errored field)I can't find a way to do this in Blazor.
Describe the solution you'd like
I need a way to do
ModelState.AddModelError
in Blazor. Is it possible to exposeModelState
altogether in Blazor?Additional context
We apparently cannot simply use custom validation annotation because the validation may be async. (aspnet/Mvc#7791 required for this behavior)
Related to issue, might qualify as separate issue:
In Blazor,
GetService
returns NULL!EDIT 2: Solved the issue, although with a different approach:
https://github.com/ryanelian/FluentValidation.Blazor
This library allows writing validators registered to the .NET Core DI, which easily allow custom logic (even async) to be developed easily!
The text was updated successfully, but these errors were encountered: