It's essential to understand how the EditForm works with Blazor SSR. In a previous version of Blazor, when you collected form data, you would typically put it into a model by binding it to the form. Then, you would send the model to the server as JSON, or if you were using Blazor Server, you could use the object directly in your code.
Either way, you weren't using the form data as actual form data.
Blazor SSR doesn't track the DOM in this way. Instead, like other Server-Side Rendered Technologies, it uses a Form Post to collect data and action on it. When your form is rendered in the browser, it has an action and method that tells the browser where to send the form when it's submitted.
Your form button, which is of type submit, no longer fires an action picked up in the browser and operated on by your code. Instead, the action fired is standard HTML, and the rules of HTML apply.
Clicking the Submit button tells the browser to gather the values from the Input Fields associated with your form. It then creates a Form-Data object that it sends back to the server to be processed. How does it know which inputs map to which fields?
Your browser uses the name attribute for this as the key for each piece of data sent back in the form-data array.
On the server side, your app needs to know how to use that data, and it does this using a nifty little attribute [SupplyParameterFromForm]. If you only have a single form, you can get away with not passing a name for the form to the attribute, but your form still needs a name for this to work. You set that name like so:
<EditForm Model="Input" method="post" OnValidSubmit="LoginUser" FormName="login">
FormName is Blazor SSR's identifier to map this form to a parameter. When there is more than one form, you'll need to specify which form the data is coming from in our attribute. You can do that like so:
[SupplyParameterFromForm(FormName="LoginUser")]
Now, all the pieces are in place, and when the browser sends your form to the server to be processed, Blazor SSR can map it to our property and run the associated code for submission. You can learn more about this by reading the following article:
https://www.johnnydevcraft.com/blazor-ssr-mudfields-editcontext-issues/
author
. – Ilanailangilang@
in front ofauthor
in this case, for example:<EditForm Model="author" OnValidSubmit="SaveAuthor">
– Bienne