Example of DefaultFunctionalities in ASP.NET MVC ContextMenu Control
This sample demonstrates the template functionality of the ContextMenu. Right-click or touch and hold the designated rectangular area to open the ContextMenu, which displays customized items using a template.
@Html.UiContextMenu(new UiContextMenuOptions { Id = "contextmenu", Target = "#contextmenutarget", CssClass = "e-contextMenu-template", ItemTemplate = "#contextMenuTemplate", Items = (List<UiMenuItem>)ViewData["menuItems"] })
<style>
.contextmenu-control { margin: 5% 25%; width: auto; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
#contextmenutarget { border: 1px dashed; height: 250px; padding: 10px; position: relative; text-align: center; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.e-contextMenu-template .menu-wrapper { display: flex; align-items: center; padding: 2px; }
.e-contextMenu-template .menu-wrapper .text-content { display: flex; flex-direction: column; text-align: left; }
.e-contextMenu-template .menu-wrapper .text { font-weight: 600; }
.e-contextMenu-template .menu-wrapper .description { font-size: 0.8em; }
.e-contextMenu-template .menu-wrapper .icon-right { padding: 8px 8px 8px 0; font-size: 1.5em; }
.e-contextMenu-template .ui-nav-link { height: auto; line-height: normal; }
.glyph-list-unordered::before { content: ""; display: inline-block; width: 1em; height: 1em; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 10.5c-.83 0-1.5.67-1.5 1.5s.67 1.5 1.5 1.5 1.5-.67 1.5-1.5-.67-1.5-1.5-1.5zm0-6c-.83 0-1.5.67-1.5 1.5S3.17 7.5 4 7.5 5.5 6.83 5.5 6 4.83 4.5 4 4.5zm0 12c-.83 0-1.5.68-1.5 1.5s.68 1.5 1.5 1.5 1.5-.68 1.5-1.5-.67-1.5-1.5-1.5zM7 19h14v-2H7v2zm0-6h14v-2H7v2zm0-8v2h14V5H7z'/%3E%3C/svg%3E") no-repeat center / contain; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 10.5c-.83 0-1.5.67-1.5 1.5s.67 1.5 1.5 1.5 1.5-.67 1.5-1.5-.67-1.5-1.5-1.5zm0-6c-.83 0-1.5.67-1.5 1.5S3.17 7.5 4 7.5 5.5 6.83 5.5 6 4.83 4.5 4 4.5zm0 12c-.83 0-1.5.68-1.5 1.5s.68 1.5 1.5 1.5 1.5-.68 1.5-1.5-.67-1.5-1.5-1.5zM7 19h14v-2H7v2zm0-6h14v-2H7v2zm0-8v2h14V5H7z'/%3E%3C/svg%3E") no-repeat center / contain; }
.glyph-check-box::before { content: ""; display: inline-block; width: 1em; height: 1em; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z'/%3E%3C/svg%3E") no-repeat center / contain; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z'/%3E%3C/svg%3E") no-repeat center / contain; }
.glyph-caption::before { content: ""; display: inline-block; width: 1em; height: 1em; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 4v3h5.5v12h3V7H19V4z'/%3E%3C/svg%3E") no-repeat center / contain; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 4v3h5.5v12h3V7H19V4z'/%3E%3C/svg%3E") no-repeat center / contain; }
.glyph-text-form::before { content: ""; display: inline-block; width: 1em; height: 1em; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M2.5 4v3h5v12h3V7h5V4h-13zm19 5h-9v3h3v7h3v-7h3V9z'/%3E%3C/svg%3E") no-repeat center / contain; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M2.5 4v3h5v12h3V7h5V4h-13zm19 5h-9v3h3v7h3v-7h3V9z'/%3E%3C/svg%3E") no-repeat center / contain; }
.glyph-text-wrap::before { content: ""; display: inline-block; width: 1em; height: 1em; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z'/%3E%3C/svg%3E") no-repeat center / contain; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z'/%3E%3C/svg%3E") no-repeat center / contain; }
.glyph-mouse-pointer::before { content: ""; display: inline-block; width: 1em; height: 1em; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z'/%3E%3C/svg%3E") no-repeat center / contain; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z'/%3E%3C/svg%3E") no-repeat center / contain; }
</style>
<template id="contextMenuTemplate">
<div class="menu-wrapper">
<span class="${IconCss} icon-right"></span>
<div class="text-content">
<span class="text">${Text}</span>
<span class="description">${Description}</span>
</div>
</div>
</template>
<div class="control-section">
<div class="contextmenu-control">
<div id="contextmenutarget">Right click/Touch hold to open the Context Menu and select the answer type</div>
@Html.UiContextMenu(new UiContextMenuOptions { Id = "contextmenu", Target = "#contextmenutarget", CssClass = "e-contextMenu-template", ItemTemplate = "#contextMenuTemplate", Items = (List<UiMenuItem>)ViewData["menuItems"] })
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class ContextMenuController : Controller
{
// The page is Views/ContextMenu/TemplateFunctionalities.cshtml; it draws what ViewData holds.
public ActionResult TemplateFunctionalities()
{
ViewData["menuItems"] = new List<UiMenuItem>
{
new UiMenuItem { Text = "Selection", IconCss = "glyph glyph-list-unordered", Data = new { Text = "Selection", Description = "Choose from options", IconCss = "glyph glyph-list-unordered" } },
new UiMenuItem { Text = "Yes / No", IconCss = "glyph glyph-check-box", Data = new { Text = "Yes / No", Description = "Select Yes or No", IconCss = "glyph glyph-check-box" } },
new UiMenuItem { Text = "Text", IconCss = "glyph glyph-caption", Data = new { Text = "Text", Description = "Type own answer", IconCss = "glyph glyph-caption" }, Items = new List<UiMenuItem>
{
new UiMenuItem { Text = "Single line", IconCss = "glyph glyph-text-form", Data = new { Text = "Single line", Description = "Type answer in a single line", IconCss = "glyph glyph-text-form" } },
new UiMenuItem { Text = "Multiple line", IconCss = "glyph glyph-text-wrap", Data = new { Text = "Multiple line", Description = "Type answer in multiple lines", IconCss = "glyph glyph-text-wrap" } }
} },
new UiMenuItem { Text = "None", IconCss = "glyph glyph-mouse-pointer", Data = new { Text = "None", Description = "No answer required", IconCss = "glyph glyph-mouse-pointer" } }
};
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>
ContextMenu is a graphical user interface that appears on a right-click or touch-and-hold action. It supports displaying single-level or multi-level menus and allows for customizing the menu items through templates.
In this demo, itemTemplate property is used to enable template support for customizing ContextMenu items. Each menu item is customized using a template to include icons, descriptive text, and additional content, offering a flexible and user-friendly interface.
In mobile, the sub menu opens in a single layer with option for switching back to parent menu.