Using Telerik UI HtmlHelpers and TagHelpers in a Razor Class Library Project
Environment
Product | Telerik UI for ASP.NET Core |
Description
How can I use Telerik UI for ASP.NET Core HtmlHelpers and TagHelpers components in a Razor Class Library applications?
Solution
-
Create a new ASP.NET Core application.
-
Choose the Project Template:
-
In the project template search box, type Razor Class Library.
-
Select the Razor Class Library template.
-
In the Additional information dialog, ensure the Support pages and views option is selected, if you plan to include Razor views. By default, only Razor Pages are supported.
-
-
Install Telerik UI for ASP.NET Core:
- Open the NuGet Package Manager.
- Search for Telerik.UI.for.AspNet.Core and install it.
-
Add the Views folder:
- Right-click your RCL project in Solution Explorer.
- Select Add > New Folder
- Name the folder Views.
-
Add the
_ViewImports.cshtml
file:- Right-click the Views folder
- Select Add > New Item
- Choose Razor View and name it _ViewImports.cshtml
-
Configure the
_ViewImports.cshtml
file:Razor@using Kendo.Mvc.UI @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper *, Kendo.Mvc
-
Add Razor Views:
-
Add a new Razor view to your RCL application (for example,
~/Views/Shared/_Index.cshtml
). -
Define the desired HtmlHelper or TagHelper component in the created view.
Razor@(Html.Kendo().Button() .Name("button") .Content("Click") )
-
-
Reference the RCL in your main project:
- Right-click your main project.
- Select Add > Project Reference and choose your RCL project.
-
Use the views from the RCL by referecing them in the main project:
Razor@Html.Partial("_Index")