Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Why the ValidationMessage component does not show error message in Blazor wasm when using the EditContext

$
0
0

I create a form with Blazor wasm and I use the EditContext attribute (not the Model attribute)

<EditForm EditContext="@FormEditContext"  OnSubmit="@HandleSubmitAsync">

The problem I have is with the ValidationMessage component in my razor page: it does not show the error message.If I use the Model attribute instead of EditContext attribute, the ValidationMessage work well, it show the error message...

The code that handle the submit is:

[Parameter]public EventCallback<bool> ValidationResult { get; set; }public async Task HandleSubmitAsync(){   bool isValid = FormEditContext.Validate();   await ValidationResult.InvokeAsync(isValid);}

for now, nothing is done by the ValidationResult handler... so this is not a problem...

I create the EditContext like this:

private EditContext FormEditContext;protected override Task OnInitializedAsync(){   FormEditContext = new EditContext(MyModel);   return base.OnInitializedAsync();}

In the razor page I use the ValidationMessage component like this:

<ValidationMessage For=@(() => MyModel.FirstName)></ValidationMessage>

My model implement IValidatableObject and in the Validate function return validation lie this:

yield return new ValidationResult("FirstName required", new[] { "FirstName" });

For information, the ValidationSummary component show the error message..


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>