Getting Started with Blazor Calendar Component

4 Nov 20255 minutes to read

This guide shows how to add the Blazor Calendar component to a Blazor WebAssembly app using Visual Studio and Visual Studio Code. It targets modern .NET and Blazor WebAssembly tooling.

To get started quickly with the Blazor Calendar component, refer to the following video or the GitHub sample.

Prerequisites

Create a new Blazor App in Visual Studio

Create a Blazor WebAssembly App using Visual Studio via Microsoft templates or the Syncfusion® Blazor Extension.

Install Syncfusion® Blazor Calendars and Themes NuGet in the App

To add the Blazor Calendar component, open the NuGet Package Manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), then search for and install Syncfusion.Blazor.Calendars and Syncfusion.Blazor.Themes. Alternatively, run the following Package Manager commands:

Install-Package Syncfusion.Blazor.Calendars -Version 31.2.12
Install-Package Syncfusion.Blazor.Themes -Version 31.2.12

NOTE

Syncfusion® Blazor components are available on nuget.org. See the NuGet packages topic for a list of available packages.

Prerequisites

Create a new Blazor App in Visual Studio Code

Create a Blazor WebAssembly App using Visual Studio Code via Microsoft templates or the Syncfusion® Blazor Extension.

Alternatively, create a WebAssembly application using the following commands in the terminal (Ctrl+`):

dotnet new blazorwasm -o BlazorApp
cd BlazorApp

Install Syncfusion® Blazor Calendars and Themes NuGet in the App

  • Press Ctrl+` to open the integrated terminal in Visual Studio Code.
  • Ensure you are in the project root directory where the .csproj file is located.
  • Run the following commands to install Syncfusion.Blazor.Calendars and Syncfusion.Blazor.Themes and restore dependencies:
dotnet add package Syncfusion.Blazor.Calendars -v 31.2.12
dotnet add package Syncfusion.Blazor.Themes -v 31.2.12
dotnet restore

NOTE

Syncfusion® Blazor components are available on nuget.org. See the NuGet packages topic for a list of available packages.

Register Syncfusion® Blazor Service

Open ~/_Imports.razor and import the Syncfusion.Blazor and Syncfusion.Blazor.Calendars namespaces.

@using Syncfusion.Blazor
@using Syncfusion.Blazor.Calendars

Now register the Syncfusion® Blazor service in ~/Program.cs for your Blazor WebAssembly app.

using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Syncfusion.Blazor;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(serviceProvider => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

builder.Services.AddSyncfusionBlazor();
await builder.Build().RunAsync();
....

Add stylesheet and script resources

The theme stylesheet and script are provided via NuGet Static Web Assets. Include the stylesheet and script references in the <head> section of ~/index.html:

<head>
    ....
    <link href="_content/Syncfusion.Blazor.Themes/bootstrap5.css" rel="stylesheet" />
    <script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>
</head>

NOTE

See Blazor Themes for available themes and reference methods (Static Web Assets, CDN, and CRG). For script options, see Adding Script Reference.

Add Blazor Calendar component

Add the Syncfusion® Blazor Calendar component to ~/Pages/Index.razor:

<SfCalendar TValue="DateTime"></SfCalendar>
  • Press Ctrl+F5 (Windows) or +F5 (macOS) to launch the application. The Syncfusion® Blazor Calendar component renders in your default web browser.
Blazor Calendar Component

Setting the Value, Min, and Max dates

The Calendar component provides an option to select a date within a specified range by defining the Min and Max properties. You can also set a date value within a specific range using the Value property. For more information, refer to the Date Range section. Min and Max are inclusive boundaries; out-of-range dates are disabled.

Here, the Calendar allows selecting a date from the 5th to the 27th of the current month. TValue specifies the type of the Calendar component.

<SfCalendar TValue="DateTime" Min='@MinDate' Value='@DateValue' Max='@MaxDate'></SfCalendar>

@code{
    public DateTime MinDate {get;set;} = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 05);
    public DateTime MaxDate {get;set;} = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 27);
    public DateTime DateValue {get;set;} = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 15);
}
Selection in Blazor Calendar Component

See also

NOTE

Explore the Blazor Calendar Example that shows how to render and configure the Calendar.