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

When is it appropriate to define method="post" in Blazor?

$
0
0

I am cross-referencing the source code from the template (generated via the CLI or the IDE's GUI) with the source code provided in this documentation.


On my project with auto-generated codes for CRUD setup:

<EditForm method="post" Model="someModel" OnValidSubmit="UpdateSomeModel" FormName="edit" Enhance>    // other fields here<button type="submit" class="btn btn-primary">Save</button></EditForm>

However, on my other EditForm instance:

<EditForm method="post" EditContext="editContext" OnValidSubmit="VerifySomeOtherModel" FormName="reviewSomeOtherModel" Enhance>    // other fields here<button @onclick="Discard" type="button" class="btn btn-outline-danger w-100 text-wrap">Discard</button></EditForm>

I defined the other buttons with type="button" because I found out that it is a workaround to bypass the submission of the EditForm (i.e., validation purposes), where I needed to simply go through some other simpler approach. Please read this for reference: Blazor preventDefault on submit form.

Now, I was comparing the above code snippet with this documentation, which I'll quote:

<EditForm Model="Model" OnSubmit="Submit" FormName="Starship1"><div><label> Identifier:<InputText @bind-Value="Model!.Id" /></label></div><div><button type="submit">Submit</button></div></EditForm>

and this:

<form method="post" @onsubmit="Submit" @formname="starship-plain-form"><AntiforgeryToken /><div><label> Identifier: <InputText @bind-Value="Model!.Id" /></label></div><div><button type="submit">Submit</button></div></form>

I hope that someone could provide a link to a credible source for the documentation so I can understand it more. I was planning to follow the documentation instead of the auto-generated code in my VS Code, but I needed reassurance before doing so. Probably, I was just worried not to break the essence of DOM-related work or related stuff regarding this context.

Can someone explain the difference in the use of method="post" in the context of <form> and <EditForm>?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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