Implement Syncfusion Blazor Block Editor for modular, block-based rich content creation. ALWAYS use when building structured document editors with customizable blocks like headings, paragraphs, lists, and media. Immediately configure menus, drag-drop, undo/redo, paste cleanup, and events.
The Syncfusion Blazor Block Editor is a powerful, modular content creation component that enables users to build rich, structured documents using customizable blocks. Each block represents a specific content type—headings, paragraphs, lists, tables, images, code blocks, and more—providing a clean, organized editing experience.
/), context menu (right-click), block action menu (hover), and inline toolbar (text selection)📄 Read: references/getting-started.md
📄 Read: references/editor-menus.md
📄 Read: references/built-in-blocks.md
📄 Read: references/drag-drop-and-undo.md
📄 Read: references/content-handling.md
📄 Read: references/advanced-methods.md
📄 Read: references/advanced-features.md
@using Syncfusion.Blazor.BlockEditor
@rendermode InteractiveAuto
<div id="container" style="height: 500px; width: 100%;">
<SfBlockEditor @bind-Blocks="blockData" EnableDragAndDrop="true">
<BlockEditorCommandMenu></BlockEditorCommandMenu>
<BlockEditorContextMenu Enable="true"></BlockEditorContextMenu>
<BlockEditorActionMenu Enable="true"></BlockEditorActionMenu>
<BlockEditorInlineToolbar Enable="true"></BlockEditorInlineToolbar>
<BlockEditorPasteCleanup AllowedStyles="@(new string[] { "font-weight", "font-style", "text-decoration" })"
DeniedTags="@(new string[] { "script", "iframe" })">
</BlockEditorPasteCleanup>
</SfBlockEditor>
</div>
@code {
private List<BlockModel> blockData = new List<BlockModel>
{
new BlockModel
{
BlockType = BlockType.Heading,
Properties = new HeadingBlockSettings { Level = 1 },
Content = new List<ContentModel>
{
new ContentModel { ContentType = ContentType.Text, Content = "Welcome to Block Editor" }
}
},
new BlockModel
{
BlockType = BlockType.Paragraph,
Content = new List<ContentModel>
{
new ContentModel { ContentType = ContentType.Text, Content = "Start typing or use / to add new blocks..." }
}
}
};
}
Monitor document changes in real-time for auto-save or logging:
<SfBlockEditor BlockChanged="@OnBlockChanged"
SelectionChanged="@OnSelectionChanged">
</SfBlockEditor>
@code {
private void OnBlockChanged(BlockChangedEventArgs args)
{
// Auto-save, track changes, update UI
}
private void OnSelectionChanged(SelectionChangedEventArgs args)
{
// Update toolbar state based on selection
}
}
Display finalized content without editing:
<SfBlockEditor @bind-Blocks="blockData" ReadOnly="true">
</SfBlockEditor>
Override default shortcuts for application-specific commands:
<SfBlockEditor KeyConfig="@customShortcuts">
</SfBlockEditor>
@code {
private Dictionary<string, string> customShortcuts = new()
{
{ "Bold", "alt+b" },
{ "Italic", "alt+i" }
};
}
Control paste behavior for safety and consistency:
<BlockEditorPasteCleanup AllowedStyles="@allowedStyles"
DeniedTags="@deniedTags"
PlainText="false">
</BlockEditorPasteCleanup>
@code {
private string[] allowedStyles = { "font-weight", "font-style" };
private string[] deniedTags = { "script", "iframe", "object" };
}
| Property | Type | Default | Purpose |
|---|---|---|---|
Blocks | List<BlockModel> | Empty | The content blocks bound to the editor |
Width | string | "100%" | Editor container width |
Height | string | "auto" | Editor container height |
ReadOnly | bool | false | Enable/disable read-only mode |
EnableDragAndDrop | bool | true | Enable/disable block dragging |
UndoRedoStack | int | 30 | Maximum undo/redo history depth |
CssClass | string | "" | Custom CSS classes for styling |
KeyConfig | Dictionary<string, string> | Default shortcuts | Custom keyboard shortcuts |