Example of Template in ASP.NET MVC Tooltip Control
This sample demonstrates the Template functionalities of the Tooltip which will open by hover or touch-hold action on Toolbar option.
${Name}
${Description}
@Html.UiToolbar(new UiToolbarOptions { Id = "Toolbar", Items = (List<UiToolbarItem>)ViewData["tbItems"] })
@Html.UiTooltip(new UiTooltipOptions { Id = "Tooltip", Target = "#Toolbar [title]", Content = "Tooltip", ShowTipPointer = false, Width = "170px", Position = UiTooltipPosition.BottomCenter, OnBeforeOpen = "onBeforeRender" })
<style>
.control-section { padding: 10px 15px; }
.property-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 8px 0; }
.toolbarContainer { max-width: 400px; margin: 40px auto; }
.ui-tip-content h6 { margin: 0 0 4px; font-size: 14px; }
.ui-tip-content p { margin: 0; font-size: 12px; }
</style>
<template id="toolbarTipTemplate"><div><h6>${Name}</h6><p>${Description}</p></div></template>
<div class="control-section">
<div id="targetContainer" class="control-section">
<div class="toolbarContainer">
@Html.UiToolbar(new UiToolbarOptions { Id = "Toolbar", Items = (List<UiToolbarItem>)ViewData["tbItems"] })
</div>
</div>
@Html.UiTooltip(new UiTooltipOptions { Id = "Tooltip", Target = "#Toolbar [title]", Content = "Tooltip", ShowTipPointer = false, Width = "170px", Position = UiTooltipPosition.BottomCenter, OnBeforeOpen = "onBeforeRender" })
</div>
<script>
// Syncfusion: beforeRender gives each toolbar item its own content: the name of the command and what it does
var data = [
{
"title": "Bold",
"name": "Bold (Ctrl+B)",
"description": "Makes your text bold."
},
{
"title": "Underline",
"name": "Underline (Ctrl+U)",
"description": "Underline your text."
},
{
"title": "Italic",
"name": "Italic (Ctrl+I)",
"description": "Italicize your text."
},
{
"title": "Cut",
"name": "Cut (Ctrl+X)",
"description": "Remove the selection and put it on the Clipboard so you can paste it somewhere else."
},
{
"title": "Copy",
"name": "Copy (Ctrl+C)",
"description": "Put a copy of a selection on the Clipboard so you can paste it somewhere else."
},
{
"title": "Paste",
"name": "Paste (Ctrl+V)",
"description": "Add content on the Clipboard to your document."
}
];
function onBeforeRender(args) {
for (var i = 0; i < data.length; i++) {
if (data[i].title === (args.target.getAttribute('data-ui-tip-title') || args.target.getAttribute('title'))) {
args.template = '#toolbarTipTemplate';
args.values = { Name: data[i].name, Description: data[i].description };
}
}
}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class TooltipController : Controller
{
// The page is Views/Tooltip/Template.cshtml; it draws what ViewData holds.
public ActionResult Template()
{
ViewData["tbItems"] = new List<UiToolbarItem>
{
new UiToolbarItem { IconCss = "e-icons e-cut", TooltipText = "Cut" },
new UiToolbarItem { IconCss = "e-icons e-copy", TooltipText = "Copy" },
new UiToolbarItem { IconCss = "e-icons e-paste", TooltipText = "Paste" },
new UiToolbarItem { Type = UiToolbarItemType.Separator },
new UiToolbarItem { IconCss = "e-icons e-bold", TooltipText = "Bold" },
new UiToolbarItem { IconCss = "e-icons e-underline", TooltipText = "Underline" },
new UiToolbarItem { IconCss = "e-icons e-italic", TooltipText = "Italic" }
};
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>
This sample illustrates the way to display the template content on the tooltip. With the usage of template, the user can format and structure the HTML content to be displayed on the tooltip as per their application needs.
In this sample, the tooltip is integrated with toolbar component to display the respective icon’s information. Here, the HTML template design is compiled and then the resultant output display is directly assigned to the contentproperty of the tooltip. The template compilation process needs to be done on the beforeRender event of the tooltip.