Example of Default Functionalities in ASP.NET MVC Mention Control
This sample demonstrates the default functionalities of the Mention component. Type the @@ character in the editable element and select or tag the user from the suggestion list.
@Html.UiMention(new UiMentionOptions
{
Id = "comments",
Target = "commentsMention",
MentionChar = "@",
DataSource = (IEnumerable<DropdownsDemoController.SportsData>)ViewData["sports"],
Fields = new UiDropDownFields { Text = "Name" }
})
<style>
#mention-controls { margin: 0 auto; width: 400px; padding-top: 30px; }
#mention-controls label { display: block; font-weight: 600; margin-bottom: 6px; }
#mention-controls .dropdown-sample-target { min-height: 120px; border: 1px solid #ced4da; border-radius: 4px; padding: 8px; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<div class="control-section">
<div id="mention-controls">
<label class="default-size">Comments</label>
<div id="commentsMention" class="dropdown-sample-target" contenteditable="true" role="textbox" aria-label="Comments"></div>
@Html.UiMention(new UiMentionOptions
{
Id = "comments",
Target = "commentsMention",
MentionChar = "@",
DataSource = (IEnumerable<DropdownsDemoController.SportsData>)ViewData["sports"],
Fields = new UiDropDownFields { Text = "Name" }
})
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class MentionController : Controller
{
// The page is Views/Mention/DefaultFunctionalities.cshtml; it draws what ViewData holds.
public ActionResult DefaultFunctionalities()
{
ViewData["sports"] = new SportsData().SportsList();
return View();
}
public class SportsData
{
public string Name { get; set; }
public string Eimg { get; set; }
public string EmailId { get; set; }
public List<SportsData> SportsList()
{
List<SportsData> mention = new List<SportsData>();
mention.Add(new SportsData { Name = "Selma Rose", Eimg = "3", EmailId = "selma@gmail.com" });
mention.Add(new SportsData { Name = "Russo Kay", Eimg = "8", EmailId = "russo@gmail.com" });
mention.Add(new SportsData { Name = "Camden Kate", Eimg = "9", EmailId = "camden@gmail.com" });
// ... 19 more rows
return mention;
}
}
}
}
@* 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 the users can select or tag from the list suggested. You can use the @ mention support with the input, textarea, and contenteditable div elements.
In the above sample, the div elements are configured with @ mentions listing the comments contents.