Example of Disabled Functionalities in ASP.NET MVC Mention Control
This sample demonstrates the disabled items functionalities of the Mention component. Type the @@ character in the editable element and you will notice that the disabled items are greyed out and cannot be selected.
${Name} ${EmailId}
@Html.UiMention(new UiMentionOptions
{
Id = "disableditem",
Target = "disabledMention",
MentionChar = "@",
AllowSpaces = true,
ItemTemplate = "#mentionItem",
NoRecordsText = "No item related to the search",
DisplayTemplate = "#mentionDisplay",
PopupWidth = "250px",
PopupHeight = "200px",
DataSource = (IEnumerable<DropdownsDemoController.DisabledEmailData>)ViewData["emails"],
Fields = new UiDropDownFields { Text = "Name", Disabled = "State" }
})
<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; }
.listItems { display: flex; align-items: center; gap: 8px; }
.mentionEmpImage { width: 32px; height: 32px; border-radius: 50%; }
.listItems .person { font-weight: 600; }
.listItems .email { font-size: 12px; opacity: .7; margin-left: auto; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<template id="mentionItem"><div class="listItems"><img class="mentionEmpImage" src="@Url.Content("~/Content/dropdownlist/images/Employees/")${Eimg}.png" alt="employee"/><span class="person"> ${Name} </span><span class="email">${EmailId}</span></div></template>
<template id="mentionDisplay">${Name}</template>
<div class="control-section">
<div id="mention-controls">
<label id="disabled-size">Compose your content</label>
<div id="disabledMention" class="dropdown-sample-target" contenteditable="true" role="textbox" aria-label="Compose your content"></div>
@Html.UiMention(new UiMentionOptions
{
Id = "disableditem",
Target = "disabledMention",
MentionChar = "@",
AllowSpaces = true,
ItemTemplate = "#mentionItem",
NoRecordsText = "No item related to the search",
DisplayTemplate = "#mentionDisplay",
PopupWidth = "250px",
PopupHeight = "200px",
DataSource = (IEnumerable<DropdownsDemoController.DisabledEmailData>)ViewData["emails"],
Fields = new UiDropDownFields { Text = "Name", Disabled = "State" }
})
</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/DisabledItems.cshtml; it draws what ViewData holds.
public ActionResult DisabledItems()
{
ViewData["emails"] = new DisabledEmailData().DisabledEmailList();
return View();
}
public class DisabledEmailData
{
public string Name { get; set; }
public string Eimg { get; set; }
public string EmailId { get; set; }
public bool State { get; set; }
public List<DisabledEmailData> DisabledEmailList()
{
List<DisabledEmailData> email = new List<DisabledEmailData>();
email.Add(new DisabledEmailData { Name = "Selma Rose (inactive)", Eimg = "3", EmailId = "selma@gmail.com", State = true });
email.Add(new DisabledEmailData { Name = "Russo Kay", Eimg = "8", EmailId = "russo@gmail.com", State = false });
email.Add(new DisabledEmailData { Name = "Camden Kate", Eimg = "9", EmailId = "camden@gmail.com", State = false });
// ... 19 more rows
return email;
}
}
}
}
@* 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 provides options for individual items to be in either an enabled or disabled state for specific scenarios. Once an item is disabled, it cannot be select a particular item. To configure the disabled item columns, use the fields.disabled property.