Hey Reader,
This week, let's dive deep into the world of Blazor, specifically the render modes in .NET 8. There's a lot of buzz and a bit of confusion around this, so let's clear the air.
Below is a crisp 20-minute guide on Blazor SSR (Static Server-Side Rendering), Blazor Server, WebAssembly, and the intriguing Auto Render Mode. Dive in and enjoy!
Short on time? Don't sweat it! Here are the essential nuggets about the render modes. Firstly, to tap into the power of all render modes, start by setting up a Blazor Web App project. Opt for WebAssembly or Auto for the "Interactive render mode" during setup. This gives you a head start with two projects (server and client) ready to roll.
Keep an eye on two crucial lines in the Program.cs file. If you're configuring your app to switch from no render mode or just the Server render mode, you'll need these lines:
Note: In my example, "MyButton" is a component of the client project. You can replace it with any component of your choice. Typically, the "Counter" class is used in template examples.
No client project yet? No worries. Use the Blazor WebAssembly Standalone App template to set one up. Remember to link it as a project reference to the server project and include the NuGet package Microsoft.AspNetCore.Components.WebAssembly.Server.
With this setup, you're all set to explore every render mode. Just remember to place any component or page you want to use with WebAssembly or Auto render mode in the client project. It's a key step.
Also, don't forget to add the @rendermode directive. You can place it at the top of a page or component, or tailor it for each component's use.
Here’s how you do it for an entire page:
And for an individual component:
Got questions or need more clarity? Just hit reply to this email, and I'll eagerly whip up more video tutorials to help you out.
A big shoutout to our fantastic community, and a heartfelt thanks to my Patrons for your incredible support. You're the rockstars of this newsletter and my channel.
Can't wait to see what we'll achieve together this year. Stay safe, and remember, the joy is in the coding! 💻
Take care,
Patrick
Become a .NET & Blazor expert with weekly tutorials featuring best practices and the latest improvements, right in your inbox.
Hey friend, I just released a new video and wanted to share it with you. Watch the video here 👇 I used GitHub Copilot to build a small Blazor weather app. It worked almost instantly and even used real API calls. At first glance, everything looked great. Then I opened the Razor file. All the logic was sitting in one place. UI, API calls, and business logic mixed together. It worked, but it was not something I would ship. In the video, I show how I fix this using a single refactoring prompt. I...
Hey friend, I just released a new video and I think you will enjoy this one. In the video, I ask GitHub Copilot to build a real mortgage app in Blazor. The app works. But the code is messy. All the business logic ends up in the UI. Fast results. Bad structure. Then I clean it up properly. Same behavior. Same output. Much better code using services, interfaces, and dependency injection. It shows why Copilot is powerful, but dangerous without rules. Watch the video here 👇 Enjoy the breakdown...
Hey friend, I just released a new video and I think you’ll enjoy it. In the video, I ask GitHub Copilot to build a .NET Web API using a short, vague prompt. The result works, but the structure feels random and messy. Then I run the same idea again with a stronger prompt that forces a clean structure. Feature folders. Vertical slice. Mediator. Fluent Validation. The difference is night and day. Watch the video here 👇 Enjoy the breakdown and let me know what you think. Take care, Patrick P.S....