Example of Inline in ASP.NET MVC Rich Text Editor Control
This sample demonstrates the toolbar show on inline mode. Toolbar will appear when you select the below editable content and it will hide when you focus out from the edit area.
Properties
@Html.UiRichTextEditor(new UiRichTextEditorOptions
{
Id = "inlineEditor",
InlineMode = new UiRichTextInlineMode { Enable = true, OnSelection = true },
ToolbarSettings = new UiRichTextToolbar { Items = (List<string>)ViewData["Tools"] },
Format = new UiRichTextFormat { Width = "auto" },
Value = (string)ViewData["RTEValue"]
})
@Html.UiRichTextEditor(new UiRichTextEditorOptions
{
Id = "inlineEditor",
InlineMode = new UiRichTextInlineMode { Enable = true, OnSelection = true },
ToolbarSettings = new UiRichTextToolbar { Items = (List<string>)ViewData["Tools"] },
Format = new UiRichTextFormat { Width = "auto" },
Value = (string)ViewData["RTEValue"]
})
<div class="demo-property-panel">
<h3>Properties</h3>
<div class="demo-property-row"><label for="selectOnly">Show on Selection</label><input id="selectOnly" type="checkbox" checked /></div>
</div>
<script>
document.getElementById('selectOnly').addEventListener('change', function (e) {
window.Lumen.get('inlineEditor').setSettings({ inlineMode: { onSelection: e.target.checked } });
});
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class RichTextEditorController : Controller
{
// The page is Views/RichTextEditor/Inline.cshtml; it draws what ViewData holds.
public ActionResult Inline()
{
ViewData["Tools"] = new List<string> { "Formats", "|", "Bold", "Italic", "FontColor", "BackgroundColor", "|", "CreateLink", "Image", "CreateTable", "|", "UnorderedList", "OrderedList" };
ViewData["RTEValue"] = "<h2>Inline Rich Text Editor!</h2><p>Click on this text to edit dynamically. The formatting toolbar will appear only when you select the content.</p>" +
"<h5>Features:</h5><ul><li><strong>Minimal UI:</strong> The editor is clean and distraction-free.</li>" +
"<li><strong>Contextual Toolbar:</strong> The toolbar appears only when text is selected.</li>" +
"<li><strong>Rich Formatting:</strong> Supports bold, italic, underline, lists, links, and more.</li>" +
"<li><strong>Seamless Editing:</strong> Works like a native text field but with powerful styling options.</li></ul>" +
"<blockquote><p>Try selecting this text to see the toolbar in action!</p></blockquote>";
return View();
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
The Rich Text Editor provides an option to display the toolbar on demand using the InlineMode property. Set Enable to true
to make an inline editor. The toolbar becomes visible only when the content is selected (OnSelection).