Use the Blazor sample to create two widgets that use Blazor components:
Microsoft.AspNetCore.Components.nupkg
NOTE: The instructions in this sample use Visual Studio 2022 and a Sitefinity renderer project named Renderer.
The sample works by wrapping the Blazor component (CalculatorComponent.razor) into a view component (CalculatorViewComponent.cs), which is displayed in the WYSIWYG editor as a widget. By using the out-of-the-box implementation for view components and their integration into the WYSIWYG editor, you can configure the Blazor components via the autogenerated designers.
CalculatorComponent.razor
CalculatorViewComponent.cs
You can then pass the configured values into the Blazor component as parameters through the view of the view component (Default.cshtml). You achieve this by calling the RenderComponent method: @(await Html.RenderComponentAsync<CalculatorComponent> (RenderMode.Server, new {Title = @Model.Title }))
Default.cshtml
RenderComponent
@(await Html.RenderComponentAsync<CalculatorComponent> (RenderMode.Server, new {Title = @Model.Title }))
NOTE: The Blazor widgets work with the rendering modes Server and ServerPrerendered.
Server
ServerPrerendered
There is the option to conditionally display content during the editing of the page. You can achieve this with the help of the NavigationManager class. The Calculator component (CalculatorComponent.razor) inherits from a base class called BlazorBase.cs that holds two methods IsEdit and IsPreview. They are used to determine the current state of the page - whether it is opened in edit or not.
NavigationManager
BlazorBase.cs
IsEdit
IsPreview
Under your Renderer project, you must create the following folders:
Renderer
Components
Entities
Calculator
ViewComponents
Views
Shared
Authorized
You create a special layout file for pages that will hold the Blazor components. The key points is: <script src="_framework/blazor.server.js"></script> This includes the Blazor framework in the HTML. It is important to have it right before the closing <body> tag
<script src="_framework/blazor.server.js"></script>
<body>
Perform the following:
Views/Shared
To have the current user available in the Blazor components, you create a custom authentication provider class. Perform the following:
Perform the following
Entities/Calculator
Views/Shared/Components/Calculator
Views/Shared/Components/Authorized
You integrate ASP.NET Core Blazor framework in your project by modifying the Program.cs file to include the necessary Blazor services and endpoints. You also need to register the authentication provider.
Program.cs
The Program.cs file should look in the following way:
Build your solution.
When you open your Renderer application and open the New editor, you will see the Authorized and the Calculator widgets in the widget selector. When you add the widgets on your page, you can see the currently logged user and a calculator widget, where you can perform simple operations.
Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.
This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.
This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important