Getting Started with ASP.NET Core using Razor pages

23 Jul 20267 minutes to read

This article provides step-by-step instructions for building ASP.NET Core application with ASP.NET Core DataGrid control using razor pages in Visual Studio and Visual Studio Code.

Create an ASP.NET Core Web App with Razor Pages

Create an ASP.NET Core Web App using Visual Studio via Microsoft Templates or the ASP.NET Core Extension. For detailed instructions, refer to the ASP.NET Core Web App Getting Started documentation.

Run the following command to create a new ASP.NET Core Web App.

dotnet new webapp -o RazorPagesMovie
code -r RazorPagesMovie

Alternatively, create an ASP.NET Core Web App using Visual Studio Code via Microsoft Templates, or the ASP.NET Core Extension, or the C# Dev Kit extension.

Install the required ASP.NET Core package

Install Syncfusion.AspNetCore.Grid and Syncfusion.AspNetCore.Themes NuGet packages. All Syncfusion ASP.NET Core packages are available in nuget.org. See the NuGet packages topic for the details.

  1. Go to Tools → NuGet Package Manager → Manage NuGet Packages for Solution.
  2. Search the required NuGet packages (Syncfusion.AspNetCore.Grid and Syncfusion.AspNetCore.Themes) and install them.

Alternatively, you can install the same packages using the Package Manager Console with the following commands.

Install-Package Syncfusion.AspNetCore.Grid -Version 34.1.29
Install-Package Syncfusion.AspNetCore.Themes -Version 34.1.29

Open the terminal and run the following commands.

dotnet add package Syncfusion.AspNetCore.Grid -v 34.1.29
dotnet add package Syncfusion.AspNetCore.Themes -v 34.1.29

Add the ASP.NET Core Tag Helpers

After the package is installed, open the ~/Pages/_ViewImports.cshtml file and import the Syncfusion.AspNetCore.Base and Syncfusion.AspNetCore.Grid Tag Helpers.

@addTagHelper *, Syncfusion.AspNetCore.Base
@addTagHelper *, Syncfusion.AspNetCore.Grid

Add stylesheet and script resources

The theme stylesheet and script can be referenced from CDN. Include the stylesheet and script references inside the <head> of ~/Pages/Shared/_Layout.cshtml

<head>
    ...
    <!-- ASP.NET Core controls styles -->
    <link rel="stylesheet" href="_content/Syncfusion.AspNetCore.Themes/styles/fluent2.css" />
    <!-- ASP.NET Core controls scripts -->
    <script src="_content/Syncfusion.AspNetCore.Grid/scripts/sf-grid.min.js"></script>
</head>

Register the Script Manager

Open the ~/Pages/Shared/_Layout.cshtml file and register the script manager <ejs-scripts> at the end of the <body> element as follows.

<body>
    ...
    <!-- ASP.NET Core Script Manager -->
    <ejs-scripts></ejs-scripts>
</body>

Add the ASP.NET Core DataGrid control

Add the ASP.NET Core DataGrid control in the ~/Pages/Index.cshtml file.

@page
@model IndexModel
 
@{
    List<Order> orders = new List<Order>
    {
        new Order(10248, "Ana Trujillo", new DateTime(2025,1,12), "France", 32.38),
        new Order(10249, "Martin Sommer", new DateTime(2025,1,15), "Germany", 11.61),
        new Order(10250, "Thomas Hardy", new DateTime(2025,2,5), "Brazil", 65.83),
        new Order(10251, "Elizabeth Lincoln", new DateTime(2025,2,18), "France", 41.34),
        new Order(10252, "Victoria Ashworth", new DateTime(2025,3,10), "Belgium", 51.30),
        new Order(10253, "Martine Rance", new DateTime(2025,3,22), "Brazil", 58.17)
    };
}
 
<ejs-grid id="Grid" dataSource="@orders">
    <e-grid-columns>
        <e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="CustomerID" headerText="Customer ID" width="150"></e-grid-column>
        <e-grid-column field="OrderDate" headerText="Order Date" width="130" textAlign="Right" format="yMd"></e-grid-column>
        <e-grid-column field="Freight" headerText="Freight" width="100" textAlign="Right" format="C2"></e-grid-column>
        <e-grid-column field="ShipCountry" headerText="Ship Country" width="120"></e-grid-column>
    </e-grid-columns>
</ejs-grid>
public class IndexModel : PageModel
{
    public void OnGet() { }
}

public class Order
{
    public Order() { }
    public Order(int id, string customer, DateTime date, string country, double freight)
    {
        this.OrderID = id;
        this.CustomerID = customer;
        this.OrderDate = date;
        this.ShipCountry = country;
        this.Freight = freight;
    }

    public int? OrderID { get; set; }
    public string CustomerID { get; set; }
    public DateTime? OrderDate { get; set; }
    public string ShipCountry { get; set; }
    public double? Freight { get; set; }
}

Run the application

Press Ctrl+F5 (Windows) or +F5 (macOS) to launch the application. The ASP.NET Core DataGrid control will render in your default web browser.

Open the terminal and run the following command.

dotnet run

ASP.NET Core DataGrid with Columns Data

See also

  1. Getting Started with ASP.NET Core MVC using Tag Helper
  2. Getting Started with ASP.NET Core MVC using HTML Helper