Example of @ Mention in ASP.NET MVC Rich Text Editor Control
This example shows how to integrate @@mention component within Rich Text Editor component. Type @@ character and select a user from the suggestion list.
@Html.UiRichTextEditor(new UiRichTextEditorOptions
{
Id = "mentionEditor",
Name = "Message",
Height = "260px",
ToolbarSettings = new UiRichTextToolbar { Items = (List<string>)ViewData["Tools"] },
Value = (string)ViewData["RTEValue"]
})
@Html.UiMention(new UiMentionOptions
{
Id = "rteMention",
Target = "mentionEditor_content",
ShowMentionChar = true,
Highlight = true,
PopupWidth = "240px",
Items = new[]
{
new UiListItem("maria@example.com", "Maria Santos"), new UiListItem("ken@example.com", "Ken Ito"), new UiListItem("ana@example.com", "Ana Ruiz"),
new UiListItem("bob@example.com", "Bob Martin"), new UiListItem("lena@example.com", "Lena Fischer"), new UiListItem("omar@example.com", "Omar Haddad")
}
})
@Html.UiRichTextEditor(new UiRichTextEditorOptions
{
Id = "mentionEditor",
Name = "Message",
Height = "260px",
ToolbarSettings = new UiRichTextToolbar { Items = (List<string>)ViewData["Tools"] },
Value = (string)ViewData["RTEValue"]
})
@Html.UiMention(new UiMentionOptions
{
Id = "rteMention",
Target = "mentionEditor_content",
ShowMentionChar = true,
Highlight = true,
PopupWidth = "240px",
Items = new[]
{
new UiListItem("maria@example.com", "Maria Santos"), new UiListItem("ken@example.com", "Ken Ito"), new UiListItem("ana@example.com", "Ana Ruiz"),
new UiListItem("bob@example.com", "Bob Martin"), new UiListItem("lena@example.com", "Lena Fischer"), new UiListItem("omar@example.com", "Omar Haddad")
}
})
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/Mention.cshtml; it draws what ViewData holds.
public ActionResult Mention()
{
ViewData["RTEValue"] = "<p>Hello team, please review the release notes. </p>";
ViewData["Tools"] = new List<string> { "Bold", "Italic", "Underline", "|", "UnorderedList", "|", "Undo", "Redo" };
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 @Mention is a component used to display a list of items that users can select or tag from the suggested list. In this demo, configured the following properties with popup dimensions.
allowSpaces- Allows to search a word with space.suggestionCount- Control the items in suggestion list.itemTemplate- Used to display the customized appearance in suggestion list.