Skip to main content
All docs
V25.2
  • Create a Blazor Web App in VS Code

    • 3 minutes to read

    This help topic contains step-by-step instructions on how to create and run a Blazor Server web application with DevExpress components in Visual Studio Code.

    Create and Run a Project

    1. Open Visual Studio Code and switch to the Explorer view.
    2. Click the New DevExpress Project button.
    3. Specify the project name and press Enter.
    4. Select a project location and click the Select Folder button.
    5. Click Blazor in the left pane of the Template Kit window.

      Template Kit - Basic Blazor Project

    6. Click the Create Project button and wait for the project to open in Visual Studio Code.

    7. If prompted, trust the project folder to unlock all features.

      Trust the Project Folder

    8. Open the Run and Debug view.

    9. Select “C#…” from the dropdown and then select “C#: BlazorWebApp [Default Configuration]”.

      Select Project Configuration

    10. Click the Start Debugging button.

      Run the Project

    Visual Studio Code builds the project, and automatically opens the app’s home page in a web browser.

    Basic DevExpress Blazor Project

    Add a DevExpress Blazor Component to the App

    To get acquainted with the project structure, add a simple DevExpress Blazor component (Calendar) to the app and see it in action:

    1. Switch to the Explorer view.
    2. Create and open Calendar.razor file under ComponentsPages.
    3. Define a component as a routable page that can handle requests from http://localhost:####/calendar. Use the following directive:

      @page "/calendar"
      
    4. The DevExpress Calendar for Blazor does not support static render mode. Enable interactivity:

      @rendermode InteractiveServer
      
    5. Add a page title and heading text:

      <PageTitle>Calendar</PageTitle>
      <h1>Calendar</h1>
      
    6. Add the DxCalendar component to the page. Bind the component to the SelectedDate variable to test interactivity.

      <DxCalendar @bind-SelectedDate="@SelectedDate" />
      
      <p><b>Selected date:</b> @SelectedDate.ToLongDateString()</p>
      
      @code {
          DateTime SelectedDate { get; set; } = DateTime.Now;
      }
      
    7. Add a link to the page in the application’s sidebar. Open the ComponentsLayoutNavMenu.razor file and add a new DxMenuItem:

      <DxMenuItem NavigateUrl="/calendar"
                  Text="Calendar"
                  CssClass="@MenuItemCssClass("/calendar")"
                  IconCssClass="icon icon-demos" />
      
    8. Open the Run and Debug view and re-run the project.

      Blazor Calendar Component

    Full code:

    @page "/calendar"
    @rendermode InteractiveServer
    
    <PageTitle>Calendar</PageTitle>
    <h1>Calendar</h1>
    
    <DxCalendar @bind-SelectedDate="@SelectedDate" />
    
    <p><b>Selected date:</b> @SelectedDate.ToLongDateString()</p>
    
    @code {
        DateTime SelectedDate { get; set; } = DateTime.Now;
    }