Skip to content

Event handlers in layout do not seem to fire in a .NET 8 RC1 blazor application #50712

Closed
@akorchev

Description

@akorchev

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Originally reported as a problem with the Radzen.Blazor component library which we maintain. After troubleshooting it turned out that no event handlers are firing (no exceptions or any other problems).

I tested without Radzen.Blazor and managed to reproduce the problem with a vanilla button click handler taken from the Counter.razor component that comes from the default application template.

For some reason event handlers defined in the layout do not fire out of the box.

Expected Behavior

I expected event handlers in layouts to work as in earlier Blazor and .NET versions. Maybe some configuration is missing (related to the new mixed rendering model).

Steps To Reproduce

  1. Create a new .NET 8 Blazor application by running dotnet new blazor -o BlazorNET8
  2. Open Components/MainLayout.razor.
  3. Delete everything and paste
     @inherits LayoutComponentBase
    
     <div class="page">
     <div class="sidebar">
         <NavMenu />
     </div>
    
     <main>
         <div class="top-row px-4">
             <p role="status">Current count: @currentCount</p>
             <button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
             <a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
         </div>
    
         <article class="content px-4">
             @Body
         </article>
     </main>
    </div>
    
     <div id="blazor-error-ui">
     An unhandled error has occurred.
     <a href="" class="reload">Reload</a>
     <a class="dismiss">🗙</a>
     </div>
    
     @code {
     private int currentCount = 0;
    
     private void IncrementCount()
     {
         currentCount++;
     }
    }
    
  4. Run the application and try clicking the Click me button in the header. The displayed counter value remains 0 instead of incrementing. In .NET 7 this works as expected.

Exceptions (if any)

No response

.NET Version

8.0.100-rc.1.23455.8

Anything else?

I am testing on macOS (M1, Ventura 13.4.1).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions