Try out Blazor updates for .NET 6, where we try out four new features.
Blazor new features
Using Visual Studio 2022 preview, you can see how the following features work for Blazor in .NET 6:
Preserving prerendering state
.NET 5 had the ability to load a Blazor WebAssembly application to the server before being presented to the client. One of the benefits of prerendering is to make it easier for search engines to crawl an application.
However, it didn't have any ability to store data. This was a particular problem if there was an API call when the application was initialised. It would have to make the same API call twice.
.NET 6 has fixed this through the use of the
Querystring component parameters
There is now the ability to read a Razor component parameter through a querystring parameter. This is thanks to the
In addition, it also allows us to specify the querystring parameter name to map the property to.
Modify page title from a Razor component
With .NET 6, we can add a page title to a Razor component. And it's dynamic as well.
<PageTitle> tag, we display the number of notes being shown on the screen. This updates automatically when a note is added.
If we want to catch an exception for a particular element of a page, such as a call to a child Razor component, we can do this through the
This allows us to customise the error for a particular element of the page.
This is the software that will need to be installed onto your machine.
- Visual Studio 2022 Preview 3.1 or above. It will work with the free community version.
- .NET 6.0 SDK Preview 7 or above. Visual Studio 2022 should already have the .NET SDK installed.
Get the application working
These are the steps to get the application working.
- Fill out the source code form. We will send you an email where you can download the source code.
You are now ready to go.
Open the project in Visual Studio
RoundTheCode.BlazorDotNet6.sln in Visual Studio 2022.
Start the project in Visual Studio. As we are prerendering the Blazor WebAssembly application, it should be the
RoundTheCode.BlazorDotNet6.Host project that is set as the startup project.
https://localhost:4500, to test out the Blazor .NET 6 updates.
Watch our video where we go ahead and implement these four new Blazor features for .NET 6.
In addition, we describe these changes in detail with our article "Blazor updates for .NET 6 using Visual Studio 2022".