I was having issues with .NET 8 Blazor Web App events and getting them to trigger. It started when my @bind-Value on my textarea wasn’t populating my booking.Text property. But I did some experimenting and it turns out that none of my delegate event handlers are working.
I isolated the issue to a new project with just that in it – No change
I restarted my PC – No change
I reinstalled visual studio 2022 – No change
I checked my setup, –version and –list-sdks:
I couldn’t hit the breakpoint and the console didn’t contain the string from the console.writeline()
I’m convinced there is something wrong with my setup somehow. I just don’t know what. I just need ideas of things to try really. Thanks in advance!
2
Answers
This is probably the result of the render mode. Microsoft doc
If you migrate from an old version to .net read this doc
The primary suspect is the following in App.razor:
<Routes />
<HeadOutlet />
. Those should both have the parameter rendermode:<Routes @rendermode="InteractiveWebAssembly" />
This is configured in the project creation wizard:
If you select Global it is configured for your entire project. With Per page/component (default) you have to configure it for every page/component. Global used to be the default/only-option in .net7 and before.
After running the code provided, i found that the console message was being printed to the web browsers console. (F12 then go to console). and it was hitting the break points also.
checking the rendermode in routes to be
<Routes @rendermode="InteractiveAuto">
and also checking to see if you have
<ItemGroup> <ProjectReference Include="..StackOverflowQuestionButton.ClientStackOverflowQuestionButton.Client.csproj" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.1" /> </ItemGroup>
included in your
<Project></Project>
in TestProject