Search code examples
blazorblazor-server-sideserver-side-renderingprerender.net-8.0

Blazor Web App component content renders twice - how to change render mode (.NET 8)?


I have used Blazor Server previously (.NET 6) but am new to .NET 8. I created a new Blazor Web project (interactive render mode: auto, interactivity mode: per page/component). My server component content is rendering twice. In earlier versions of Blazor I could prevent this by changing the render mode in the _Host.cshtml file (see Blazor rendering content twice) but this file is not present in the new Blazor Web App.

How do I change the render mode in .NET 8 in order to render content once?

I have already tried adding @rendermode InteractiveServer to the top of my Home page as well as adding <Routes @rendermode="RenderMode.InteractiveServer" /> to my App.razor file but the page continues to render twice.


Solution

  • Found the issue. Dumb error but I will go ahead and post the solution just in case someone runs into the same problem. I had transferred some previously-written code into MainLayout.razor and didn't notice that the @Body statement was listed twice (in two places within the document).