Skip to content
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

.NET 8 Blazor - OnChange() Migration To Static Rendering #54018

Closed
1 task done
sbwalker opened this issue Feb 13, 2024 · 2 comments
Closed
1 task done

.NET 8 Blazor - OnChange() Migration To Static Rendering #54018

sbwalker opened this issue Feb 13, 2024 · 2 comments
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved

Comments

@sbwalker
Copy link

sbwalker commented Feb 13, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When migrating Blazor component logic to utilize the Static rendering approach, you need to replace interactive event handlers with static equivalents.

For example, for @onclick events:

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

you can use a form-based approach:

<form method="post" @onsubmit="IncrementCount" @formname="MyUniqueForm">
    <AntiforgeryToken />
    <button type="submit" class="btn btn-primary">Click me</button>
</form>

However for @onchange events:

<select name="name" class="form-select" value="@_name" @onchange="(e => NameChanged(e))">
@foreach (var name in _names)
{
    <option value="@name">@name</option>
}
</select>

There are currently no recommendations or functional examples.

Expected Behavior

Provide documentation examples on the recommended approach for migrating interactive @onchange events to static alternatives.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

8.0.1

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Feb 13, 2024
@sbwalker sbwalker changed the title Blazor .NET 8 - OnChange() Equivalent In Static Rendering Blazor .NET 8 - OnChange() Migration To Static Rendering Feb 13, 2024
@sbwalker sbwalker changed the title Blazor .NET 8 - OnChange() Migration To Static Rendering .NET 8 Blazor - OnChange() Migration To Static Rendering Feb 13, 2024
@javiercn
Copy link
Member

@sbwalker thanks for contacting us.

The recommended approach on those situations is to use interactivity and avoid SSR or use JS to hook into the change event via JS.

It's a non-goal to make every interactive scenario possible via SSR. It's up to the developer to choose when to apply each, but in general, SSR interactivity is limited to forms, which is the only thing that works without JS.

@javiercn javiercn added question ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. labels Feb 14, 2024
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved
Projects
None yet
Development

No branches or pull requests

2 participants