Blazor Button Onclick function submitting form
Asked Answered
L

1

12

I am facing strange issue while working on Blazor. I have a form for creating and editing records, on the same form I have table with rows and columns. In one column I am rendering delete button as shown in the screenshot.When I click on delete button it shows modal box for confirmation.

enter image description here Code : <td><button @onclick="(() => ExecuteDelete(file.fileName))">x</button></td>

When I click on this button, confirm modal box gets opened however behind the scene it is submitting the form and validation messages appear on the form. I have separate button for submitting the form.

Is this behavior correct ?? how to prevent this.

Could anyone please help in solving this issue.

Thanks

Logarithm answered 9/4, 2020 at 6:24 Comment(0)
S
27

As per spec, <button> elements are by default of type="submit" when placed within a form. Set delete buttons to explicit type="button".

<form>
  <button type="button" @onclick="(() => ExecuteDelete(file.fileName))">x</button>
</form>
Seaquake answered 9/4, 2020 at 6:42 Comment(2)
Oups, I post at the same time than you, I deleteWellrounded
Thanks its working after explicitly specifying type=buttonLogarithm

© 2022 - 2024 — McMap. All rights reserved.