What is the difference between OnValidSubmit and OnSubmit in Blazor forms?
Last updated
Both are EditForm submit callbacks, but they differ in who owns validation: OnValidSubmit fires only after validation passes, while OnSubmit fires on every submit and hands you the full validation responsibility.
OnValidSubmit(and OnInvalidSubmit):Blazor runs validation first;
OnValidSubmitruns only if the model is valid,OnInvalidSubmitonly if it isn't.Use this for the common case: let the framework validate, you just handle success.
OnSubmit:Fires on every submit regardless of validity; you must call
editContext.Validate()yourself.Use it when you need full control over the validation flow.
Mutually exclusive: Provide either
OnSubmitor theOnValidSubmit/OnInvalidSubmitpair, not both.
- https://learn.microsoft.com/en-us/aspnet/core/blazor/forms/validation?view=aspnetcore-10.0
- https://learn.microsoft.com/en-us/aspnet/core/blazor/forms/?view=aspnetcore-10.0
- https://blazor-university.com/forms/handling-form-submission/
- https://www.telerik.com/blazor-ui/documentation/components/form/events