Try out Blazor updates for .NET 6, where we try out four new features.
Using Visual Studio 2022 preview, you can see how the following features work for Blazor in .NET 6:
.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 PersistentComponentState
.
There is now the ability to read a Razor component parameter through a querystring parameter. This is thanks to the [SupplyParameterFromQuery]
attribute.
In addition, it also allows us to specify the querystring parameter name to map the property to.
With .NET 6, we can add a page title to a Razor component. And it's dynamic as well.
Using the <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 <ErrorBoundary>
tag.
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.
These are the steps to get the application working.
You are now ready to go.
Open up 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.
Hit 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.
Please note that since this video was recorded, ComponentApplicationState
has been changed to PersistentComponentState
in .NET 6 RC2. This has been updated in the article and the code example, but not the video.
In addition, we describe these changes in detail with our article "Blazor updates for .NET 6 using Visual Studio 2022".