Getting Started with ASP.NET Core Block Editor

This section explains how to add the ASP.NET Core Block Editor control to your ASP.NET Core application using Visual Studio.

Prerequisites:

  • .NET 6.0 or later (compatible up to .NET 10.0)
  • Visual Studio 2019 or later with ASP.NET and web development workload
  • Basic familiarity with ASP.NET Core Razor Pages

AI Coding Assistant: Discover the full potential of ASP.NET Core controls with AI Coding Assistant. Effortlessly integrate, configure, and enhance your projects with intelligent, context-aware code suggestions. Explore AI Coding Assistant

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 Syncfusion® ASP.NET Core Extension. For detailed instructions, refer to the ASP.NET Core Web App Getting Started documentation.

Install the required ASP.NET Core packages

To add the ASP.NET Core Block Editor control to your application, open the NuGet Package Manager in Visual Studio by going to Tools → NuGet Package Manager → Manage NuGet Packages for Solution. Search for and install the following packages:

All Syncfusion ASP.NET Core packages are available at nuget.org. For more information, see the NuGet packages documentation.

Note: The version placeholder 34.2.2 will be replaced with the actual version during documentation build. For the latest version, check the release notes.

Alternatively, install the packages using the Package Manager Console:

Install-Package Syncfusion.AspNetCore.BlockEditor -Version 34.2.2
Install-Package Syncfusion.AspNetCore.Themes -Version 34.2.2

Add the ASP.NET Core Tag Helpers

After the packages are installed, open the ~/Pages/_ViewImports.cshtml file and import the Syncfusion.AspNetCore.Base and Syncfusion.AspNetCore.BlockEditor Tag Helpers.

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

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.BlockEditor/scripts/sf-blockeditor.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 ASP.NET Core Block Editor control

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

@using Syncfusion.EJ2.BlockEditor

<div id='blockeditor-container'>
    <ejs-blockeditor id="block-editor"></ejs-blockeditor>
</div>

<style>
    #blockeditor-container {
        margin: 20px auto;
    }
</style>
public ActionResult Index()
{
    return View();
}

IMPORTANT

When the Block Editor control is rendered, the id attribute must be provided; otherwise, the control will fail to render.

Run the application

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

ASP.NET Core Block Editor Control

See Also

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