-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
blazor ssr form processing issues #51978
Comments
@Seanxwy thanks for contacting us. Can you provide more details on the types of issues you are referring to? There are a couple of things you can do, but the guidance is as follows:
In the blazor model, the page renders normally in response to a post request, and only after it has rendered the first time, it processes any action that might have been triggered by a form from the client. The reasons for this behavior are two:
|
@Seanxwy Possibly the simplest way to achieve what you're asking is just to have some |
@javiercn @SteveSandersonMS https://github.com/Seanxwy/BlazorDemo/blob/master/BlazorDemo/Components/Pages/Home.razor |
@Seanxwy something like this should work: https://github.com/Seanxwy/BlazorDemo/blob/master/BlazorDemo/Components/Pages/Home.razor#L52
```csharp
- public Address Model { get; set; } = new();
+ public Address Model { get; set; } = default!; protected override Task OnParametersSetAsync()
{
+ Model = switch (model, Id) =>
+ {
+ (null, null) => new(),
+ (var m, null) => m,
+ (null, var id) when id <= 0 => new(),
+ (null, _) => LoadData(),
+ (var m, var id) when m.Id != Id => LoadData(),
+ }
} In general, you need to move the Model to a field, as it's going to cause problems if you use the prop as a state variable. The general recommendation is:
|
I think this is not a good way to handle it, and it is not friendly to multi-forms and complex scenarios |
@Seanxwy thanks for the additional details. Sure, I might have oversimplified this and made it more complex. In the end, it can be done as follows public override OnInitialized()
{
Model ??= new();
}
public override OnParametersSet()
{
if(Id != Model.Id) {
LoadData()
}
} The only time you really worry about SSR and |
This is just a simple example, but the actual project will face very complex problems. I really want to use ssr a lot to improve the performance of the project. But at present ssr makes people feel that the completion is very low, I am sorry that the project can only continue to maintain the server mode. However, the interaction performance and experience of server mode are greatly affected by the stability of the network. While 8.0 is a huge improvement, it's still not very satisfying |
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes. See our Issue Management Policies for more information. |
Is there an existing issue for this?
Describe the bug
Blazor SSR form submission issue
When submitting a form on a page, OnInitialized and OnParametersSetAsync execute as if the page had just opened before executing the method specified by OnInvalidSubmit.
This causes the logic in OnInitialized and OnParametersSetAsync to be executed multiple times. (For example, for a DataList + QueryCondition form, when the query form is submitted, the query logic is executed first, and then the query condition is processed. (More problematic if there are multiple forms on the page).
Is there a way to recognize POST operations so that POST operations and objects are recognized in OnInitialized or OnParametersSetAsync and the logic is processed as required?
Expected Behavior
When the form is submitted, it is desirable to identify whether the request is GET or POST in OnInitialized or OnParametersSetAsync.
Something like the Razor Pages handler to make it explicit.
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
8.0 -rc2
Anything else?
No response
The text was updated successfully, but these errors were encountered: