New to Telerik UI for ASP.NET CoreStart a free 30-day trial

Using Telerik UI HtmlHelpers and TagHelpers in a Razor Class Library Project

Environment

ProductTelerik 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

  1. Create a new ASP.NET Core application.

  2. Choose the Project Template:

    • In the project template search box, type Razor Class Library.

    • Select the Razor Class Library template.

      Select 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.

      Select Razor Class Library template

  3. Install Telerik UI for ASP.NET Core:

    • Open the NuGet Package Manager.
    • Search for Telerik.UI.for.AspNet.Core and install it.
  4. Add the Views folder:

    • Right-click your RCL project in Solution Explorer.
    • Select Add > New Folder
    • Name the folder Views.
  5. Add the _ViewImports.cshtml file:

    • Right-click the Views folder
    • Select Add > New Item
    • Choose Razor View and name it _ViewImports.cshtml
  6. Configure the _ViewImports.cshtml file:

    Razor
    @using Kendo.Mvc.UI
    @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
    @addTagHelper *, Kendo.Mvc
  7. 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")
          )
  8. Reference the RCL in your main project:

    • Right-click your main project.
    • Select Add > Project Reference and choose your RCL project.
  9. Use the views from the RCL by referecing them in the main project:

    Razor
    @Html.Partial("_Index")

See Also

In this article
EnvironmentDescriptionSolutionSee Also
Not finding the help you need?
Contact Support