Example of Default Functionalities in ASP.NET MVC Tooltip Control
This sample demonstrates the default functionalities of the Tooltip which will open by hover or touch-hold action on button and displayed in 12 different positions.
Position
@Html.UiButton(new UiButtonOptions { Id = "btn", Text = "Show Tooltip" })
@Html.UiTooltip(new UiTooltipOptions { Id = "Tooltip", Target = "#btn", Content = "Let's go green to save the planet!!", Position = UiTooltipPosition.TopCenter })
@Html.UiDropDownList("positions", new UiDropDownListOptions { Width = "160px", Value = "TopCenter", OnChange = "onChange", Items = ((string[])ViewData["positions"]).Select(p => new UiListItem(p, System.Text.RegularExpressions.Regex.Replace(p, "([a-z])([A-Z])", "$1 $2"))).ToList() })
<style>
.control-section { padding: 10px 15px; }
.property-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 8px 0; }
</style>
<div class="control-section">
<div id="tooltipHost" style="padding: 60px 20px;">
@Html.UiButton(new UiButtonOptions { Id = "btn", Text = "Show Tooltip" })
</div>
@Html.UiTooltip(new UiTooltipOptions { Id = "Tooltip", Target = "#btn", Content = "Let's go green to save the planet!!", Position = UiTooltipPosition.TopCenter })
</div>
<div class="demo-property-panel property-section" title="Properties">
<div class="property-row"><span>Position</span> @Html.UiDropDownList("positions", new UiDropDownListOptions { Width = "160px", Value = "TopCenter", OnChange = "onChange", Items = ((string[])ViewData["positions"]).Select(p => new UiListItem(p, System.Text.RegularExpressions.Regex.Replace(p, "([a-z])([A-Z])", "$1 $2"))).ToList() })</div>
</div>
<script>
// Syncfusion: the list sets the position of the Tooltip
function onChange(value) { if (value) { window.Lumen.get('Tooltip').setPosition(value); } }
</script>
using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class TooltipController : Controller
{
// The page is Views/Tooltip/DefaultFunctionalities.cshtml; it draws what ViewData holds.
public ActionResult DefaultFunctionalities()
{
ViewData["positions"] = new string[] { "TopLeft", "TopCenter", "TopRight", "BottomLeft", "BottomCenter", "BottomRight", "LeftTop", "LeftCenter", "LeftBottom", "RightTop", "RightCenter", "RightBottom" };
return View();
}
private ActionResult Show()
{
LayoutSample sample = (LayoutSample)ViewBag.LayoutSample;
// A sample keeps its data in a Prepare<Page> method (LayoutDemoController.Samples.cs); it puts what the page reads in ViewData.
string page = sample.Source.Substring(sample.Source.LastIndexOf('_') + 1);
System.Reflection.MethodInfo prepare = GetType().GetMethod("Prepare" + page, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (prepare != null) { prepare.Invoke(this, null); }
return View("PreparedSample", ViewData.Model);
}
}
}
@* 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>
@* Layouts with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
This sample illustrates a tooltip, that gets opened on hovering the target labelled Show Tooltip. The tooltip can be shown on 12 possible positions, by selecting the appropriate position values provided in the dropdown. The applicable tooltip positions are as follows:
TopLeftTopCenterTopRightBottomLeftBottomCenterBottomRightLeftTopLeftCenterLeftBottomRightTopRightCenterRightBottom
In case, if the tooltip needs to be opened on mobile devices, tap hold on the target labelled Show Tooltip instead of hovering and by default, it closes after 1.5 seconds on lift.