How can I help you?
Getting Started with Blazor Web App
6 Mar 20266 minutes to read
This article provides step-by-step instructions for building a Blazor Web App with the Blazor DataGrid component using Visual Studio, Visual Studio Code, and the .NET CLI.
To get started quickly with a Blazor Web App, watch the following video.
Using Playground
Blazor Playground allows you to interact with our Blazor components directly in your web browser without need to install any required NuGet packages. By default, the Syncfusion.Blazor package is included in this.
Using Syncfusion® Blazor Templates
You can create a Blazor Web App using Syncfusion® Blazor Templates in both Visual Studio and Visual Studio Code.
Manually Creating a Project
This section provides a brief guide on how to manually create a Blazor Web App.
Prerequisites
Create a new Blazor Web App in Visual Studio
You can create a Blazor Web App using Visual Studio via Microsoft Templates or the Syncfusion® Blazor Extension.
Prerequisites
Create a new Blazor Web App in Visual Studio Code
You can create a Blazor Web App using Visual Studio Code via Microsoft Templates or the Syncfusion® Blazor Extension.
For example, in a Blazor Web App with the Auto interactive render mode, use the following commands.
dotnet new blazor -o BlazorWebApp -int Auto
cd BlazorWebApp
cd BlazorWebApp.ClientPrerequisites
Latest version of the .NET SDK. If you previously installed the SDK, you can determine the installed version by executing the following command in a command prompt (Windows) or terminal (macOS) or command shell (Linux).
dotnet --versionCreate a Blazor Web App using .NET CLI
Run the following command to create a new Blazor Web App in a command prompt (Windows) or terminal (macOS) or command shell (Linux).
For example, in a Blazor Web App with the Auto interactive render mode, use the following commands.
dotnet new blazor -o BlazorWebApp -int Auto
cd BlazorWebApp
cd BlazorWebApp.ClientThis command creates a new Blazor Web App and places it in a new directory called BlazorWebApp inside your current location. See the Create a Blazor App and dotnet new CLI command topics for more details.
NOTE
Configure the appropriate Interactive render mode and Interactivity location while creating a Blazor Web App. For detailed information, refer to the interactive render mode documentation.
Install Syncfusion® Blazor packages
Install Syncfusion.Blazor.Grid and Syncfusion.Blazor.Themes packages into your project.
If using the WebAssembly or Auto render modes in the Blazor Web App, install this packages in the client project.
NOTE
All Syncfusion Blazor packages are available on nuget.org. See the NuGet packages topic for details.
Add Import Namespaces
After the packages installed, open the ~/_Imports.razor file in the client project and import the Syncfusion.Blazor and Syncfusion.Blazor.Grids namespaces.
@using Syncfusion.Blazor
@using Syncfusion.Blazor.GridsRegister Syncfusion® Blazor Service
Register the Syncfusion® Blazor Service in the Program.cs file of your Blazor Web App.
...
using Syncfusion.Blazor;
...
builder.Services.AddSyncfusionBlazor();
....NOTE
If the Interactive Render Mode is set to
WebAssemblyorAuto, register the Syncfusion® Blazor service in Program.cs files of both server and client project in the Blazor Web App.
Add stylesheet and script resources
The theme stylesheet and script can be accessed from NuGet through Static Web Assets. Include the stylesheet and the script reference in the App.razor file.
<link href="_content/Syncfusion.Blazor.Themes/fluent2.css" rel="stylesheet" />
...
<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>NOTE
Check out the Blazor Themes topic to discover various methods (Static Web Assets, CDN, and CRG) for referencing themes in your Blazor application. Also, check out the Adding Script Reference topic to learn different approaches for adding script references in your Blazor application.
Add Syncfusion® Blazor DataGrid component
Add the Syncfusion® Blazor DataGrid component in the ~/Components/Pages/*.razor file. If the interactivity location is set to Per page/component in the Web App, define a render mode at the top of the ~Pages/*.razor component. (e.g. InteractiveServer, InteractiveWebAssembly or InteractiveAuto).
NOTE
If an Interactivity is set to
GlobalwithAutoorWebAssembly, the render mode is already configured in theApp.razorfile by default.
@* desired render mode define here *@
@rendermode InteractiveAuto@using Syncfusion.Blazor.Grids
<SfGrid DataSource="@Orders" />
@code{
public List<Order> Orders { get; set; }
protected override void OnInitialized()
{
Orders = Enumerable.Range(1, 10).Select(x => new Order()
{
OrderID = 1000 + x,
CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],
Freight = 2 * x,
OrderDate = DateTime.Now.AddDays(-x),
}).ToList();
}
public class Order {
public int? OrderID { get; set; }
public string CustomerID { get; set; }
public DateTime? OrderDate { get; set; }
public double? Freight { get; set; }
}
}- Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to launch the application. This will render the Syncfusion® Blazor DataGrid component in the default web browser.