Example of API in ASP.NET MVC Tooltip Control
This sample demonstrates how to customize the tooltip component by using its properties from the property pane. Select any combination of properties from the property pane to customize tooltips.
Content
Height
Width
Open Mode
Sticky Mode
@Html.UiButton(new UiButtonOptions { Id = "default", Text = "Show Tooltip" })
@Html.UiTooltip(new UiTooltipOptions { Id = "tooltip", Target = "#default", Content = "Tooltip content", Position = UiTooltipPosition.TopCenter, OpensOn = UiTooltipOpensOn.Click })
@Html.UiNumericTextBox("height", new UiNumericTextBoxOptions { Value = 100, Width = "100px", OnChange = "onHeightChange" })
@Html.UiNumericTextBox("width", new UiNumericTextBoxOptions { Value = 45, Width = "100px", OnChange = "onWidthChange" })
@Html.UiDropDownList("ddlelement", new UiDropDownListOptions { Width = "120px", Value = "Click", OnChange = "onModeChange", Items = ((string[])ViewData["ddlData"]).Select(m => new UiListItem(m, m)).ToList() })
@Html.UiCheckBox("sticky", false, new UiCheckBoxOptions { Id = "sticky", OnChange = "stickyChange" })
<style>
.control-section { padding: 10px 15px; }
.property-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 8px 0; }
.prop-input { width: 130px; padding: 4px 6px; border: 1px solid var(--ui-input-border); border-radius: var(--ui-radius); background: var(--ui-surface); color: var(--ui-text); font: inherit; }
</style>
<div class="control-section">
<div id="tooltipHost" style="padding: 60px 20px;">
@Html.UiButton(new UiButtonOptions { Id = "default", Text = "Show Tooltip" })
</div>
@Html.UiTooltip(new UiTooltipOptions { Id = "tooltip", Target = "#default", Content = "Tooltip content", Position = UiTooltipPosition.TopCenter, OpensOn = UiTooltipOpensOn.Click })
</div>
<div class="demo-property-panel property-section" title="Properties">
<div class="property-row"><span>Content</span> <input id="tooltipContentValue" type="text" placeholder="Tooltip content" class="prop-input" /></div>
<div class="property-row"><span>Height</span> @Html.UiNumericTextBox("height", new UiNumericTextBoxOptions { Value = 100, Width = "100px", OnChange = "onHeightChange" })</div>
<div class="property-row"><span>Width</span> @Html.UiNumericTextBox("width", new UiNumericTextBoxOptions { Value = 45, Width = "100px", OnChange = "onWidthChange" })</div>
<div class="property-row"><span>Open Mode</span> @Html.UiDropDownList("ddlelement", new UiDropDownListOptions { Width = "120px", Value = "Click", OnChange = "onModeChange", Items = ((string[])ViewData["ddlData"]).Select(m => new UiListItem(m, m)).ToList() })</div>
<div class="property-row"><span>Sticky Mode</span> @Html.UiCheckBox("sticky", false, new UiCheckBoxOptions { Id = "sticky", OnChange = "stickyChange" })</div>
</div>
<script>
// Syncfusion: the property panel sets the content, the size, the open mode and the sticky mode of the Tooltip
var size = { width: null, height: null };
function tip() { return window.Lumen.get('tooltip'); }
document.addEventListener('input', function (e) { if (e.target.id === 'tooltipContentValue') { tip().setContent(e.target.value); } });
function onHeightChange(value) { size.height = value; tip().setSize(size.width, size.height); }
function onWidthChange(value) { size.width = value; tip().setSize(size.width, size.height); }
function onModeChange(value) { if (value) { tip().setOpensOn(value); } }
function stickyChange(on) { tip().setSticky(on); }
</script>
<script>
(function (window, document) {
'use strict';
var root = document.getElementById('layoutPreview');
if (!root) { return; }
root.addEventListener('click', function (event) {
var button = event.target.closest('[data-tip-api]');
if (!button || !root.contains(button)) { return; }
var api = window.Lumen.get('layoutTooltip');
if (!api) { window.LayoutSampleLog('Control is loading; try again.'); return; }
switch (button.getAttribute('data-tip-api')) {
case 'open': api.open(root.querySelector('#layoutTipTarget')); break;
case 'close': api.close(); break;
case 'update': api.setContent('Updated local tooltip text.'); break;
}
window.LayoutSampleLog('isOpen(): ' + api.isOpen());
});
})(window, document);
</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/Api.cshtml; it draws what ViewData holds.
public ActionResult Api()
{
ViewData["ddlData"] = new string[] { "Auto", "Hover", "Click", "Focus", "Custom" };
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. *@
In this demo, the default tooltip is rendered with minimal configuration. This sample can be customized further with the combination of tooltip properties from the property pane. For example,
- Any change made to a textbox in the property pane will be reflected in the tooltip
Content StickyModecan be enabled by checking the sticky mode option in the property pane.HeightandWidthcan be changed from the property pane.OpenModecan be changed from the property pane.