Using Telerik UI for Blazor in ASP.NET Web Applications
Environment
Product | UI for Blazor |
Description
How can I modernize my ASP.NET Core web application by adding Blazor components in it, and eventually migrate the project to Blazor?
Considerations
You can use an ASP.NET Core web application to render Blazor components by following the requirements, considerations, and steps below:
- Add Blazor to the project. This includes the client-side assets, the service, and the SignalR hub. In the sample project linked below, these are added to the layout so that all pages can use them. Make sure you don't add them twice on a certain page.
-
Add the Telerik components as usual. Add the
TelerikRootComponent
around the contents of every Blazor component. Otherwise, it is not possible to render it in a shared location like in an actual Blazor app. - Use the Blazor components according to the current framework approach by using the
<component type="typeof(MyComponent)" render-mode="ServerPrerendered" param-SomeParameter="@ObjectToPass" />
approach. In previous versions, the recommended approach was by using Razor components like partial views through theHtml.RenderComponentAsync()
helper, where you has to pass their parameters as fields in an anonymous model object. - If you wish to use Alert, Confirm, or Prompt Dialogs, you need to do this in a nested Razor component of the
TelerikRootComponent
. Otherwise, if you try to define theDialogFactory
CascadingParameter
in the same Razor component that includes theTelerikRootComponent
, then the cascading parameter will benull
. -
If you are already using Kendo UI components in such a project, make sure to only use the Telerik UI for Blazor Themes. They match the SASS-based themes from Kendo UI and you must only have one theme referenced.
It is recommended that you use the latest Kendo UI and Telerik UI for Blazor versions. If not possible, try using Kendo UI and Telerik UI for Blazor versions that are close together, so that there are as little differences in their theming as possible.
To see the full implementation of the suggested approach, go to the Razor components GitHub repo containing the sample project with comments and also other examples.