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

blazor editform and submit buttons with an @onclick

$
0
0

In my Blazor Webassembly app, I have an EditForm with two submit buttons.

Each of the submit buttons has an @onclick handler which just sets a model value so I can tell which button was pressed.

This works fine under .Net 6 and 7, the value is set and validation and submit processing proceed as usual.

Under .Net 8, the @onclick hander is called, but validation and submit do not.

Any suggestions?

I have also tried calling EditForm.EditContext.Validate in my @onclick handlers. this returns false when there are validation errors (as expected) but no error messages are displayed.

Update: It was my fault. I provided an EditContext that was a getter that generated a new EditContext on each reference. For some reason, when the submit button had some @handler validation and submit processing did not happen. Curious, but irrelevant.

Thanks for all the feedback.

@page "/Test"@using System.ComponentModel.DataAnnotations<h3>Edit</h3><EditForm EditContext="Context" OnValidSubmit=@DoSomething><DataAnnotationsValidator /><ValidationSummary /><InputText @bind-Value="@this.Text" /><button type="submit">Works</button><button type="submit" @onclick=@Whatever>Does Not Work</button></EditForm>@code {    [Required]    public string? Text { get; set; }    // EditContext Context => new(this);  *** this was the problem    EditContext Context = new(this); // *** should have been this.

Viewing all articles
Browse latest Browse all 4839

Trending Articles