Loading...
Loading...
Implement Syncfusion Block Editor control in ASP.NET Core applications using Razor Tag Helpers. Use this skill when working with Syncfusion Block Editor, EJ2 BlockEditor, ASP.NET Core block-based content editing, or <ejs-blockeditor> syntax. Covers block management, nested content structures, drag-and-drop functionality, content sanitization, installation, tag helper setup, block types, content manipulation, events, menus, and advanced features for creating rich block-based document editors.
npx skill4agent add syncfusion/aspnetcore-ui-components-skills syncfusion-aspnetcore-blockeditorInstall-Package Syncfusion.EJ2.AspNet.Core@addTagHelper *, Syncfusion.EJ2<head>
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/dist/ej2.min.css" />
</head>
<body>
@RenderBody()
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js"></script>
<ejs-scripts></ejs-scripts>
@RenderSection("Scripts", required: false)
</body>@using Syncfusion.EJ2.BlockEditor
<div id='blockeditor-container'>
<ejs-blockeditor id="block-editor" blocks="@ViewBag.BlocksData"></ejs-blockeditor>
</div>
<style>
#blockeditor-container {
margin: 20px auto;
}
</style>using Syncfusion.EJ2.BlockEditor;
public class BlockModel
{
public string id { get; set; }
public string blockType { get; set; }
public object properties { get; set; }
public List<object> content { get; set; }
}
public IActionResult Index()
{
var blocks = new List<BlockModel>
{
new BlockModel
{
id = "heading-1",
blockType = "Heading",
properties = new { level = 1 },
content = new List<object>
{
new { contentType = "Text", content = "Welcome to Block Editor" }
}
},
new BlockModel
{
id = "paragraph-1",
blockType = "Paragraph",
content = new List<object>
{
new { contentType = "Text", content = "Start creating your content with blocks!" }
}
}
};
ViewBag.BlocksData = blocks;
return View();
}var blockEditorObj = ej.base.getInstance(document.getElementById('block-editor'), ejs.blockeditor.BlockEditor);
const newBlock = {
id: 'new-paragraph',
blockType: 'Paragraph',
content: [
{
contentType: "Text",
content: 'This is a newly added block'
}
]
};
// Add after a specific block
blockEditorObj.addBlock(newBlock, 'existing-block-id', true);new BlockModel
{
blockType = "CollapsibleHeading",
content = new List<object>
{
new { contentType = "Text", content = "Section Title" }
},
properties = new
{
level = 1,
isExpanded = true,
children = new List<BlockModel>
{
new BlockModel
{
blockType = "Paragraph",
content = new List<object>
{
new { contentType = "Text", content = "Hidden content goes here" }
}
}
}
}
}<ejs-blockeditor id="block-editor">
<e-blockeditor-pastesettings
allowedStyles="@(new string[] { "font-weight", "font-style", "text-decoration" })"
deniedTags="@(new string[] { "script", "iframe", "form" })"
keepFormat="true">
</e-blockeditor-pastesettings>
</ejs-blockeditor>var commandMenuItems = new List<object>
{
new
{
id = "timestamp",
groupHeader = "Actions",
label = "Insert Timestamp",
iconCss = "e-icons e-schedule"
},
new
{
id = "separator",
type = "Divider",
groupHeader = "Utility",
label = "Insert Divider",
iconCss = "e-icons e-divider"
}
};
ViewBag.CommandMenuItems = commandMenuItems;<ejs-blockeditor id="block-editor"
readOnly="true"
blocks="@ViewBag.BlocksData">
</ejs-blockeditor>| Property | Type | Description | Default |
|---|---|---|---|
| string | Unique identifier for the Block Editor instance | - |
| List<BlockModel> | Initial block content | [] |
| string | Height of the editor (px, vh, %) | auto |
| string | Width of the editor (px, %) | 100% |
| bool | Enable read-only mode | false |
| string | Custom CSS class for styling | - |
| bool | Enable block drag-and-drop | true |
| bool | Enable right-to-left layout | false |
| string | Localization culture (e.g., "de", "es") | "en" |
| int | Number of undo/redo steps | 30 |
| object | Keyboard shortcuts configuration | default shortcuts |