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

Chart Wizard in Razor Pages

Razor Pages is an alternative to the MVC pattern that makes page-focused coding easier and more productive. This approach consists of a cshtml file and a cshtml.cs file (by design, the two files have the same name).

You can seamlessly integrate the Telerik UI Chart Wizard for ASP.NET Core in Razor Pages applications.

This article describes how to configure the Chart Wizard component in a Razor Pages scenario.

Getting Started

To connect the Chart Wizard to a data set retrieved from a remote endpoint in a Razor Pages application, proceed with the following steps:

  1. Specify the Read request URL in the DataSource configuration. The URL must refer to the method name in the PageModel.

    HtmlHelper_Index.cshtml
        @page
        @model IndexModel
    
        @(Html.Kendo().ChartWizard<Product>()
            .Name("chartwizard")
            .DataSource(dataSource => dataSource
                .Read(r => r.Url("/Index?handler=Read").Data("forgeryToken"))
            )
            .DataColumns(columns =>
            {
                columns.Add().Field(f => f.ProductName).Title("Product Name");
                columns.Add().Field(f => f.Quantity);
            })
        )
  2. Add an AntiForgeryToken at the top of the page.

    Razor
        @inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf
        @Html.AntiForgeryToken()
  3. Send the AntiForgeryToken with the Read request.

    Razor
        <script>
            function forgeryToken() {
                return kendo.antiForgeryTokens();
            }
        </script>

    Additional parameters can also be supplied.

    Razor
        <script>
            function forgeryToken() {
                return {
                    __RequestVerificationToken: kendo.antiForgeryTokens().__RequestVerificationToken,
                    additionalParameter: "test"
                }
            }
        </script>
  4. Within the cshtml.cs file, add a handler method for the Read data operation.

    Index.cshtml.cs
        public static List<Product> products;
    
        public void OnGet(string culture)
        {
            if (!String.IsNullOrEmpty(culture))
            {
                CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(culture);
            }
    
            if (products == null)
            {
                products = GetData();
            }
        }
    
        public JsonResult OnPostRead([DataSourceRequest] DataSourceRequest request, int? id)
        {
            return new JsonResult(products.ToDataSourceResult(request));
        }
    
        private static List<Product> GetData()
        {
            return new List<Product>()
            {
                new Product { ProductID = 216321, ProductName = "Calzone", Quantity = 1 },
                new Product { ProductID = 546897, ProductName = "Margarita", Quantity = 2 },
                new Product { ProductID = 456231, ProductName = "Pollo Formaggio", Quantity = 1 }
            };
        }

See Also

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