Syncfusion ASP.NET MVC Block Editor
The Block Editor control provides a block-based rich content editing experience in ASP.NET MVC applications. Content is structured as a collection of typed blocks (Paragraph, Heading, List, Code, Table, Image, etc.), each independently configurable with content, properties, and inline styles.
Quick Start Example
@using Syncfusion.EJ2.BlockEditor
<div id='blockeditor-container'>
@Html.EJS().BlockEditor("block-editor").Render()
</div>
<style>
#blockeditor-container { margin: 20px auto; }
</style>
public ActionResult Index()
{
return View();
}
With initial blocks:
@using Syncfusion.EJ2.BlockEditor
<div id='blockeditor-container'>
@Html.EJS().BlockEditor("block-editor").Blocks((List<BlockModel>)ViewBag.BlocksData).Render()
</div>
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 ActionResult 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 = "My Document" }
}
},
new BlockModel
{
id = "para-1",
blockType = "Paragraph",
content = new List<object>
{
new { contentType = "Text", content = "Start writing here." }
}
}
};
ViewBag.BlocksData = blocks;
return View();
}
Documentation and Navigation Guide
Getting Started & Installation
📄 Read: references/getting-started.md
When user needs to:
- Install
Syncfusion.EJ2.MVC5 NuGet package
- Add namespace reference in
Web.config
- Link CDN stylesheet and script in
_Layout.cshtml
- Register the Syncfusion script manager
- Render a minimal Block Editor on a page
Block Types & Configuration
📄 Read: references/block-types.md
When user needs to:
- Understand all supported block types (Paragraph, Heading, List, Code, Quote, Callout, Divider, Image, Table, Collapsible, Template)
- Configure
blockType, content, properties, indent, cssClass on individual blocks
- Set heading levels (1–4), list types (BulletList, NumberedList, Checklist), checklist
isChecked state
- Add placeholder text to blocks
- Apply per-block CSS classes for custom styling
- Use Template blocks for custom HTML content
Inline Content & Styles
📄 Read: references/inline-content.md
When user needs to:
- Configure
contentType (Text, Link, Code, Mention, Label)
- Set hyperlink properties (
url, openInNewWindow) on Link content
- Configure Label content with
labelId, trigger character (TriggerChar default: "$"), and LabelSettings
- Configure the
Users collection and UserModel for Mention content
- Configure Mention content with
userId
- Apply inline text styles: bold, italic, underline, strikethrough, color, backgroundColor, superscript, subscript, uppercase, lowercase, inlineCode
Nested Blocks (Collapsible, Quote, Callout)
📄 Read: references/nested-blocks.md
When user needs to:
- Configure CollapsibleHeading or CollapsibleParagraph with
children, isExpanded, level
- Configure Quote blocks with nested child Paragraph blocks
- Configure Callout blocks with nested children
- Set
parentId (top-level on BlockModel) to establish parent-child relationships
Embed Blocks (Image & Code)
📄 Read: references/embed-blocks.md
When user needs to:
- Render an Image block with
src, altText, width, height
- Configure global
ImageBlockSettings (saveUrl, path, saveFormat, allowedTypes, maxFileSize, enableResize)
- Upload images to a server via controller action
- Handle image upload lifecycle:
BeforeFileUpload (validate/cancel), FileUploading (add auth headers), FileUploadSuccess (read saved URL), FileUploadFailed (error feedback)
- Configure Code blocks with syntax highlighting and language selection
- Set global
CodeBlockSettings (defaultLanguage default: "javascript", languages array)
Table Blocks
📄 Read: references/table-block.md
When user needs to:
- Render a Table block with columns, rows, and cells
- Configure
enableHeader, enableRowNumbers, readOnly, width on a table
- Define column headers (
headerText) and row cells with columnId and nested blocks
- Understand table resizing and multi-row/column selection/deletion
Editor Menus
📄 Read: references/editor-menus.md
When user needs to:
- Customize the Slash Command menu (
CommandMenuSettings): popup size, custom commands, tooltip, Filtering/ItemSelect events
- Customize the Context menu (
ContextMenuSettings): enable, custom items, submenus, ShowItemOnClick, Opening/Closing/ItemSelect events
- Customize the Block Action menu (
BlockActionsMenuSettings): custom items, tooltip, popup size, Opening/Closing/ItemSelect events
- Customize the Inline Toolbar (
InlineToolbarSettings): enable, items, popup width, tooltip, ItemClick event
- Add Transform, InlineCode, Link items to the Inline Toolbar
- Configure font color and background color pickers (
FontColorSettings, BackgroundColorSettings)
Events
📄 Read: references/events.md
When user needs to:
- Handle editor lifecycle:
Created, Focus, Blur
- Respond to content changes:
BlockChanged, SelectionChanged
- Handle drag operations:
BlockDragStart, BlockDragging, BlockDropped
- Intercept paste operations:
BeforePasteCleanup, AfterPasteCleanup
- Handle image upload lifecycle:
BeforeFileUpload, FileUploading, FileUploadSuccess, FileUploadFailed
Methods
📄 Read: references/methods.md
When user needs to:
- Add, remove, move, update, or get blocks programmatically (
addBlock, removeBlock, moveBlock, updateBlock, getBlock, getBlockCount)
- Manage selection and cursor:
setSelection, setCursorPosition, getSelectedBlocks, getRange, selectRange, selectBlock, selectAllBlocks
- Manage focus:
focusIn, focusOut
- Apply formatting:
executeToolbarAction, enableToolbarItems, disableToolbarItems
- Export content:
getDataAsJson, getDataAsHtml, renderBlocksFromJson, parseHtmlToBlocks, print
- Always retrieve the component instance via
ej.base.getInstance in the Created event
Appearance & Read-Only
📄 Read: references/appearance.md
When user needs to:
- Set editor
Width and Height
- Enable
ReadOnly mode (view-only, no edits)
- Apply a custom
CssClass to the editor container
- Persist editor state across page reloads with
EnablePersistence
Paste Cleanup
📄 Read: references/paste-cleanup.md
When user needs to:
- Configure
PasteCleanupSettings: DeniedTags, KeepFormat, PlainText
- Strip unwanted tags (script, iframe) from pasted content
- Paste as plain text stripping all formatting
Undo/Redo & Keyboard Shortcuts
📄 Read: references/undo-redo-keyboard.md
When user needs to:
- Configure
UndoRedoStack size (default: 30)
- Know all built-in keyboard shortcuts for formatting, block creation, block management
- Customize shortcuts via
KeyConfig property
Globalization & Accessibility
📄 Read: references/globalization.md
When user needs to:
- Set
Locale for localized UI strings (e.g., de for German)
- Enable RTL layout with
EnableRtl
- Know the full localization key table
Drag & Drop
📄 Read: references/drag-drop.md
When user needs to:
- Enable or disable drag and drop with
EnableDragAndDrop
- Understand single vs. multiple block dragging behavior
Security (XSS Prevention)
📄 Read: references/security.md
When user needs to:
- Understand the built-in
EnableHtmlSanitizer protection (default: true)
- Know which elements are automatically removed
- Escape HTML characters in output using
EnableHtmlEncode (default: false)
Collaborative Editing
📄 Read: references/collaborative-editing.md
When user needs to:
- Set up real-time collaborative editing using Yjs and providers (y-websocket, y-webrtc, Hocuspocus, Liveblocks, PartyKit)
- Configure
CollaborationSettings with adapter and provider
- Enable user presence and remote cursors with
EnableAwareness
- Track active collaborators with
Users and CurrentUserId
- Implement version history with snapshots (create, restore, compare, export, import)
- Configure custom snapshot storage using
IVersionStorage interface (IndexedDB, database, cloud)
- Handle collaboration events:
SnapshotCreated, SnapshotRestored
- Resolve synchronization issues and optimize performance for multiple users
Key Properties at a Glance
| Property |
Type |
Purpose |
Blocks |
List<BlockModel> |
Initial block content |
Width |
string |
Editor width (e.g., "100%", "800px") |
Height |
string |
Editor height (e.g., "80vh", "500px") |
ReadOnly |
bool |
Enable view-only mode (default: false) |
CssClass |
string |
Custom CSS class on editor container |
EnableDragAndDrop |
bool |
Allow block reordering (default: true) |
UndoRedoStack |
int |
Max undo/redo steps (default: 30) |
Locale |
string |
Culture code for localization (default: "en-US") |
EnableRtl |
bool |
Right-to-left layout (default: false) |
EnableHtmlSanitizer |
bool |
XSS protection — strips dangerous tags/attrs (default: true) |
EnableHtmlEncode |
bool |
Escape special HTML characters in output (default: false) |
EnablePersistence |
bool |
Persist editor state across page reloads (default: false) |
KeyConfig |
object |
Custom keyboard shortcut overrides |
CommandMenuSettings |
object |
Slash command menu config (/ key) |
ContextMenuSettings |
object |
Right-click context menu config |
BlockActionsMenu |
object |
Block action menu config (hover drag handle) |
InlineToolbarSettings |
object |
Inline formatting toolbar config (text selection) |
TransformSettings |
object |
Block transform options in the inline toolbar |
FontColorSettings |
object |
Font color palette/picker config |
BackgroundColorSettings |
object |
Background highlight color palette/picker config |
PasteCleanupSettings |
object |
Paste content cleanup rules |
ImageBlockSettings |
object |
Global image block configuration |
CodeBlockSettings |
object |
Global code block configuration (defaultLanguage: "javascript") |
LabelSettings |
object |
Label item definitions and trigger character (default: "$") |
Users |
List<UserModel> |
User list for @ mention resolution |
Common Patterns
Pattern 1 — Get Component Instance
Always capture the instance in Created; all method calls require this reference:
var blockEditorObj;
function onCreated() {
blockEditorObj = ej.base.getInstance(
document.getElementById('block-editor'),
ejs.blockeditor.BlockEditor
);
}
@Html.EJS().BlockEditor("block-editor").Created("onCreated").Render()
Pattern 2 — Export Content as JSON
var jsonData = blockEditorObj.getDataAsJson();
// Send to server or store in state
Pattern 3 — Programmatically Add a Block
var newBlock = {
id: 'new-para',
blockType: 'Paragraph',
content: [{ contentType: 'Text', content: 'Added programmatically' }]
};
blockEditorObj.addBlock(newBlock, 'existing-block-id', true); // true = insert after
Pattern 4 — Toggle Read-Only at Runtime
blockEditorObj.readOnly = true; // enable read-only
blockEditorObj.readOnly = false; // re-enable editing
1---2name: syncfusion-aspnetmvc-blockeditor3description: Implement Syncfusion ASP.NET MVC Block Editor control. Use when building block-based rich content editors, configuring block types (Paragraph, Heading, List, Code, Table, Image, Callout, Collapsible), handling drag-and-drop, editor menus (slash command, context, block action, inline toolbar), events, methods, paste cleanup, undo/redo, globalization, appearance, collaborative editing with real-time synchronization, version history, and user presence features in ASP.NET MVC Razor views.4---56# Syncfusion ASP.NET MVC Block Editor78The Block Editor control provides a block-based rich content editing experience in ASP.NET MVC applications. Content is structured as a collection of typed blocks (Paragraph, Heading, List, Code, Table, Image, etc.), each independently configurable with content, properties, and inline styles.910## Quick Start Example1112```razor13@using Syncfusion.EJ2.BlockEditor1415<div id='blockeditor-container'>16 @Html.EJS().BlockEditor("block-editor").Render()17</div>1819<style>20 #blockeditor-container { margin: 20px auto; }21</style>22```2324```csharp25public ActionResult Index()26{27 return View();28}29```3031**With initial blocks:**3233```razor34@using Syncfusion.EJ2.BlockEditor3536<div id='blockeditor-container'>37 @Html.EJS().BlockEditor("block-editor").Blocks((List<BlockModel>)ViewBag.BlocksData).Render()38</div>39```4041```csharp42public class BlockModel43{44 public string id { get; set; }45 public string blockType { get; set; }46 public object properties { get; set; }47 public List<object> content { get; set; }48}4950public ActionResult Index()51{52 var blocks = new List<BlockModel>53 {54 new BlockModel55 {56 id = "heading-1",57 blockType = "Heading",58 properties = new { level = 1 },59 content = new List<object>60 {61 new { contentType = "Text", content = "My Document" }62 }63 },64 new BlockModel65 {66 id = "para-1",67 blockType = "Paragraph",68 content = new List<object>69 {70 new { contentType = "Text", content = "Start writing here." }71 }72 }73 };74 ViewBag.BlocksData = blocks;75 return View();76}77```7879---8081## Documentation and Navigation Guide8283### Getting Started & Installation84📄 **Read:** [references/getting-started.md](references/getting-started.md)8586When user needs to:87- Install `Syncfusion.EJ2.MVC5` NuGet package88- Add namespace reference in `Web.config`89- Link CDN stylesheet and script in `_Layout.cshtml`90- Register the Syncfusion script manager91- Render a minimal Block Editor on a page9293### Block Types & Configuration94📄 **Read:** [references/block-types.md](references/block-types.md)9596When user needs to:97- Understand all supported block types (Paragraph, Heading, List, Code, Quote, Callout, Divider, Image, Table, Collapsible, Template)98- Configure `blockType`, `content`, `properties`, `indent`, `cssClass` on individual blocks99- Set heading levels (1–4), list types (BulletList, NumberedList, Checklist), checklist `isChecked` state100- Add placeholder text to blocks101- Apply per-block CSS classes for custom styling102- Use Template blocks for custom HTML content103104### Inline Content & Styles105📄 **Read:** [references/inline-content.md](references/inline-content.md)106107When user needs to:108- Configure `contentType` (Text, Link, Code, Mention, Label)109- Set hyperlink properties (`url`, `openInNewWindow`) on Link content110- Configure Label content with `labelId`, trigger character (`TriggerChar` default: `"$"`), and `LabelSettings`111- Configure the `Users` collection and `UserModel` for Mention content112- Configure Mention content with `userId`113- Apply inline text styles: bold, italic, underline, strikethrough, color, backgroundColor, superscript, subscript, uppercase, lowercase, inlineCode114115### Nested Blocks (Collapsible, Quote, Callout)116📄 **Read:** [references/nested-blocks.md](references/nested-blocks.md)117118When user needs to:119- Configure CollapsibleHeading or CollapsibleParagraph with `children`, `isExpanded`, `level`120- Configure Quote blocks with nested child Paragraph blocks121- Configure Callout blocks with nested children122- Set `parentId` (top-level on BlockModel) to establish parent-child relationships123124### Embed Blocks (Image & Code)125📄 **Read:** [references/embed-blocks.md](references/embed-blocks.md)126127When user needs to:128- Render an Image block with `src`, `altText`, `width`, `height`129- Configure global `ImageBlockSettings` (saveUrl, path, saveFormat, allowedTypes, maxFileSize, enableResize)130- Upload images to a server via controller action131- Handle image upload lifecycle: `BeforeFileUpload` (validate/cancel), `FileUploading` (add auth headers), `FileUploadSuccess` (read saved URL), `FileUploadFailed` (error feedback)132- Configure Code blocks with syntax highlighting and language selection133- Set global `CodeBlockSettings` (defaultLanguage default: `"javascript"`, languages array)134135### Table Blocks136📄 **Read:** [references/table-block.md](references/table-block.md)137138When user needs to:139- Render a Table block with columns, rows, and cells140- Configure `enableHeader`, `enableRowNumbers`, `readOnly`, `width` on a table141- Define column headers (`headerText`) and row cells with `columnId` and nested blocks142- Understand table resizing and multi-row/column selection/deletion143144### Editor Menus145📄 **Read:** [references/editor-menus.md](references/editor-menus.md)146147When user needs to:148- Customize the Slash Command menu (`CommandMenuSettings`): popup size, custom commands, tooltip, Filtering/ItemSelect events149- Customize the Context menu (`ContextMenuSettings`): enable, custom items, submenus, ShowItemOnClick, Opening/Closing/ItemSelect events150- Customize the Block Action menu (`BlockActionsMenuSettings`): custom items, tooltip, popup size, Opening/Closing/ItemSelect events151- Customize the Inline Toolbar (`InlineToolbarSettings`): enable, items, popup width, tooltip, ItemClick event152- Add Transform, InlineCode, Link items to the Inline Toolbar153- Configure font color and background color pickers (`FontColorSettings`, `BackgroundColorSettings`)154155### Events156📄 **Read:** [references/events.md](references/events.md)157158When user needs to:159- Handle editor lifecycle: `Created`, `Focus`, `Blur`160- Respond to content changes: `BlockChanged`, `SelectionChanged`161- Handle drag operations: `BlockDragStart`, `BlockDragging`, `BlockDropped`162- Intercept paste operations: `BeforePasteCleanup`, `AfterPasteCleanup`163- Handle image upload lifecycle: `BeforeFileUpload`, `FileUploading`, `FileUploadSuccess`, `FileUploadFailed`164165### Methods166📄 **Read:** [references/methods.md](references/methods.md)167168When user needs to:169- Add, remove, move, update, or get blocks programmatically (`addBlock`, `removeBlock`, `moveBlock`, `updateBlock`, `getBlock`, `getBlockCount`)170- Manage selection and cursor: `setSelection`, `setCursorPosition`, `getSelectedBlocks`, `getRange`, `selectRange`, `selectBlock`, `selectAllBlocks`171- Manage focus: `focusIn`, `focusOut`172- Apply formatting: `executeToolbarAction`, `enableToolbarItems`, `disableToolbarItems`173- Export content: `getDataAsJson`, `getDataAsHtml`, `renderBlocksFromJson`, `parseHtmlToBlocks`, `print`174- Always retrieve the component instance via `ej.base.getInstance` in the `Created` event175176### Appearance & Read-Only177📄 **Read:** [references/appearance.md](references/appearance.md)178179When user needs to:180- Set editor `Width` and `Height`181- Enable `ReadOnly` mode (view-only, no edits)182- Apply a custom `CssClass` to the editor container183- Persist editor state across page reloads with `EnablePersistence`184185### Paste Cleanup186📄 **Read:** [references/paste-cleanup.md](references/paste-cleanup.md)187188When user needs to:189- Configure `PasteCleanupSettings`: `DeniedTags`, `KeepFormat`, `PlainText`190- Strip unwanted tags (script, iframe) from pasted content191- Paste as plain text stripping all formatting192193### Undo/Redo & Keyboard Shortcuts194📄 **Read:** [references/undo-redo-keyboard.md](references/undo-redo-keyboard.md)195196When user needs to:197- Configure `UndoRedoStack` size (default: 30)198- Know all built-in keyboard shortcuts for formatting, block creation, block management199- Customize shortcuts via `KeyConfig` property200201### Globalization & Accessibility202📄 **Read:** [references/globalization.md](references/globalization.md)203204When user needs to:205- Set `Locale` for localized UI strings (e.g., `de` for German)206- Enable RTL layout with `EnableRtl`207- Know the full localization key table208209### Drag & Drop210📄 **Read:** [references/drag-drop.md](references/drag-drop.md)211212When user needs to:213- Enable or disable drag and drop with `EnableDragAndDrop`214- Understand single vs. multiple block dragging behavior215216### Security (XSS Prevention)217📄 **Read:** [references/security.md](references/security.md)218219When user needs to:220- Understand the built-in `EnableHtmlSanitizer` protection (default: `true`)221- Know which elements are automatically removed222- Escape HTML characters in output using `EnableHtmlEncode` (default: `false`)223224### Collaborative Editing225📄 **Read:** [references/collaborative-editing.md](references/collaborative-editing.md)226227When user needs to:228- Set up real-time collaborative editing using Yjs and providers (y-websocket, y-webrtc, Hocuspocus, Liveblocks, PartyKit)229- Configure `CollaborationSettings` with adapter and provider230- Enable user presence and remote cursors with `EnableAwareness`231- Track active collaborators with `Users` and `CurrentUserId`232- Implement version history with snapshots (create, restore, compare, export, import)233- Configure custom snapshot storage using `IVersionStorage` interface (IndexedDB, database, cloud)234- Handle collaboration events: `SnapshotCreated`, `SnapshotRestored`235- Resolve synchronization issues and optimize performance for multiple users236237---238239## Key Properties at a Glance240241| Property | Type | Purpose |242|---|---|---|243| `Blocks` | List\<BlockModel\> | Initial block content |244| `Width` | string | Editor width (e.g., `"100%"`, `"800px"`) |245| `Height` | string | Editor height (e.g., `"80vh"`, `"500px"`) |246| `ReadOnly` | bool | Enable view-only mode (default: `false`) |247| `CssClass` | string | Custom CSS class on editor container |248| `EnableDragAndDrop` | bool | Allow block reordering (default: `true`) |249| `UndoRedoStack` | int | Max undo/redo steps (default: `30`) |250| `Locale` | string | Culture code for localization (default: `"en-US"`) |251| `EnableRtl` | bool | Right-to-left layout (default: `false`) |252| `EnableHtmlSanitizer` | bool | XSS protection — strips dangerous tags/attrs (default: `true`) |253| `EnableHtmlEncode` | bool | Escape special HTML characters in output (default: `false`) |254| `EnablePersistence` | bool | Persist editor state across page reloads (default: `false`) |255| `KeyConfig` | object | Custom keyboard shortcut overrides |256| `CommandMenuSettings` | object | Slash command menu config (`/` key) |257| `ContextMenuSettings` | object | Right-click context menu config |258| `BlockActionsMenu` | object | Block action menu config (hover drag handle) |259| `InlineToolbarSettings` | object | Inline formatting toolbar config (text selection) |260| `TransformSettings` | object | Block transform options in the inline toolbar |261| `FontColorSettings` | object | Font color palette/picker config |262| `BackgroundColorSettings` | object | Background highlight color palette/picker config |263| `PasteCleanupSettings` | object | Paste content cleanup rules |264| `ImageBlockSettings` | object | Global image block configuration |265| `CodeBlockSettings` | object | Global code block configuration (defaultLanguage: `"javascript"`) |266| `LabelSettings` | object | Label item definitions and trigger character (default: `"$"`) |267| `Users` | List\<UserModel\> | User list for `@` mention resolution |268269---270271## Common Patterns272273### Pattern 1 — Get Component Instance274Always capture the instance in `Created`; all method calls require this reference:275```javascript276var blockEditorObj;277function onCreated() {278 blockEditorObj = ej.base.getInstance(279 document.getElementById('block-editor'),280 ejs.blockeditor.BlockEditor281 );282}283```284```razor285@Html.EJS().BlockEditor("block-editor").Created("onCreated").Render()286```287288### Pattern 2 — Export Content as JSON289```javascript290var jsonData = blockEditorObj.getDataAsJson();291// Send to server or store in state292```293294### Pattern 3 — Programmatically Add a Block295```javascript296var newBlock = {297 id: 'new-para',298 blockType: 'Paragraph',299 content: [{ contentType: 'Text', content: 'Added programmatically' }]300};301blockEditorObj.addBlock(newBlock, 'existing-block-id', true); // true = insert after302```303304### Pattern 4 — Toggle Read-Only at Runtime305```javascript306blockEditorObj.readOnly = true; // enable read-only307blockEditorObj.readOnly = false; // re-enable editing308```