Example of Use Case in ASP.NET MVC Rich Text Editor Control
This sample demonstrates how to design forum application using Rich Text Editor. You can type the content and click reply button to post it.
Moving our reports to the new dashboard
Posted by the platform team
From next month the weekly reports open in the dashboard instead of a spreadsheet. Each chart keeps its filters, and the numbers
come straight from the warehouse. Tell us below what you would like to see first.
Comments (1)
Maria Santos
Could the sales chart show the regions side by side?
@Html.UiRichTextEditor(new UiRichTextEditorOptions
{
Id = "commentEditor",
Name = "Comment",
Height = "180px",
Placeholder = "Write a comment...",
MaxLength = 1000,
ShowCharCount = true,
ToolbarSettings = new UiRichTextToolbar
{
Position = UiRichTextToolbarPosition.Bottom,
Items = (List<string>)ViewData["Tools"]
}
})
<article class="rte-blog">
<h3>Moving our reports to the new dashboard</h3>
<p class="small text-muted">Posted by the platform team</p>
<p>
From next month the weekly reports open in the dashboard instead of a spreadsheet. Each chart keeps its filters, and the numbers
come straight from the warehouse. Tell us below what you would like to see first.
</p>
</article>
<h4 class="h6 mt-4">Comments (<span id="rteCommentCount">1</span>)</h4>
<ul class="rte-comments" id="rteComments" aria-label="Comments">
<li><strong>Maria Santos</strong><div><p>Could the sales chart show the <b>regions</b> side by side?</p></div></li>
</ul>
<p class="mb-1"><label for="commentEditor_content">Add a comment</label></p>
@Html.UiRichTextEditor(new UiRichTextEditorOptions
{
Id = "commentEditor",
Name = "Comment",
Height = "180px",
Placeholder = "Write a comment...",
MaxLength = 1000,
ShowCharCount = true,
ToolbarSettings = new UiRichTextToolbar
{
Position = UiRichTextToolbarPosition.Bottom,
Items = (List<string>)ViewData["Tools"]
}
})
<div class="rte-actions mt-2">
<button type="button" class="btn btn-primary btn-sm" id="rteCommentPost">Post comment</button>
<button type="button" class="btn btn-outline-secondary btn-sm" id="rteCommentCancel">Cancel</button>
</div>
<style>
.rte-actions { display: flex; gap: 6px; }
.rte-comments { list-style: none; padding: 0; }
.rte-comments li { padding: 8px 0; border-bottom: 1px solid var(--ui-border, #ddd); }
.rte-comments li p:last-child { margin-bottom: 0; }
</style>
<script>
(function () {
'use strict';
document.addEventListener('click', function (event) {
var editor = window.Lumen.get('commentEditor');
if (!editor) { return; }
if (event.target.id === 'rteCommentCancel') { editor.value = ''; return; }
if (event.target.id !== 'rteCommentPost') { return; }
// getHtml() is the comment made safe; a page would post it, and its server would make it safe again before storing it.
var html = editor.getHtml();
if (!editor.getText().trim()) { editor.focusIn(); return; }
var item = document.createElement('li');
var who = document.createElement('strong');
who.textContent = 'You';
var body = document.createElement('div');
body.innerHTML = html;
item.appendChild(who);
item.appendChild(body);
var list = document.getElementById('rteComments');
list.appendChild(item);
document.getElementById('rteCommentCount').textContent = String(list.children.length);
editor.value = '';
});
})();
</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/UseCase.cshtml; it draws what ViewData holds.
public ActionResult UseCase()
{
ViewData["Tools"] = new List<string> { "Bold", "Italic", "Underline", "|", "UnorderedList", "OrderedList", "|", "CreateLink", "|", "Undo", "Redo" };
return View();
}
}
}
Rich Text Editor is a WYSIWYG editing control which will reduce the effort for users while trying to express their formatting word content as HTML or Markdown format. So, Rich Text Editor can be easily customized to use for blog posting, forums as an editor for response.