Example of Tooltip in ASP.NET MVC Slider Control
This sample demonstrates the rendering of Slider component with Tooltip. Drag the thumb over the bar for selecting the values between min and max to enable the Tooltip.
Placement
ShowOn
@Html.UiSlider("slider01", new UiSliderOptions { Min = 0, Max = 100, Value = 30, Tooltip = new UiSliderTooltip { IsVisible = true, Placement = UiSliderPlacement.Before, ShowOn = UiSliderTooltipShowOn.Focus }, ShowButtons = true })
@Html.UiSlider("slider02", new UiSliderOptions { Min = 0, Max = 100, Values = (double[])ViewData["sliderValue"], Type = UiSliderType.Range, Tooltip = new UiSliderTooltip { IsVisible = true, Placement = UiSliderPlacement.Before, ShowOn = UiSliderTooltipShowOn.Focus }, ShowButtons = true })
@Html.UiDropDownList("placement", new UiDropDownListOptions { Width = "110px", Value = "Before", OnChange = "placementChange", Items = ((IEnumerable<InputsDemoController.SliderChoice>)ViewData["placement"]).Select(c => new UiListItem(c.id, c.text)).ToList() })
@Html.UiDropDownList("showOn", new UiDropDownListOptions { Width = "110px", Value = "Focus", OnChange = "showOnChange", Items = ((IEnumerable<InputsDemoController.SliderChoice>)ViewData["showon"]).Select(c => new UiListItem(c.id, c.text)).ToList() })
<style>
.control-section .control-wrapper { width: 80%; margin: 0 auto; min-width: 185px; }
.sliderwrap { margin-top: 40px; }
.sliderwrap label, .slider-labeltext { display: block; padding-bottom: 14px; font-size: 13px; font-weight: 500; user-select: none; }
.property-section .property-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<div class="control-section">
<div class="control-wrapper">
<div class="sliderwrap">
<label class="userselect">Default Slider</label>
@Html.UiSlider("slider01", new UiSliderOptions { Min = 0, Max = 100, Value = 30, Tooltip = new UiSliderTooltip { IsVisible = true, Placement = UiSliderPlacement.Before, ShowOn = UiSliderTooltipShowOn.Focus }, ShowButtons = true })
</div>
<div class="sliderwrap">
<label class="userselect">Range Slider</label>
@Html.UiSlider("slider02", new UiSliderOptions { Min = 0, Max = 100, Values = (double[])ViewData["sliderValue"], Type = UiSliderType.Range, Tooltip = new UiSliderTooltip { IsVisible = true, Placement = UiSliderPlacement.Before, ShowOn = UiSliderTooltipShowOn.Focus }, ShowButtons = true })
</div>
</div>
</div>
<div class="demo-property-panel property-section" title="Properties">
<div class="property-row"><span>Placement</span> @Html.UiDropDownList("placement", new UiDropDownListOptions { Width = "110px", Value = "Before", OnChange = "placementChange", Items = ((IEnumerable<InputsDemoController.SliderChoice>)ViewData["placement"]).Select(c => new UiListItem(c.id, c.text)).ToList() })</div>
<div class="property-row" id="slider-showon"><span>ShowOn</span> @Html.UiDropDownList("showOn", new UiDropDownListOptions { Width = "110px", Value = "Focus", OnChange = "showOnChange", Items = ((IEnumerable<InputsDemoController.SliderChoice>)ViewData["showon"]).Select(c => new UiListItem(c.id, c.text)).ToList() })</div>
</div>
<script>
// Syncfusion: the lists set where the tooltip of both sliders is, and when it shows
function sliders() { return [window.Lumen.get('slider01'), window.Lumen.get('slider02')]; }
function placementChange(value) { if (value) { sliders().forEach(function (s) { s.setTooltip({ placement: value }); }); } }
function showOnChange(value) { if (value) { sliders().forEach(function (s) { s.setTooltip({ showOn: value }); }); } }
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class RangeSliderController : Controller
{
// The page is Views/RangeSlider/Tooltip.cshtml; it draws what ViewData holds.
public ActionResult Tooltip()
{
ViewData["sliderValue"] = new double[] { 30, 70 };
ViewData["placement"] = new List<SliderChoice> { new SliderChoice("Before", "Before"), new SliderChoice("After", "After") };
ViewData["showon"] = new List<SliderChoice> { new SliderChoice("Auto", "Auto"), new SliderChoice("Always", "Always"), new SliderChoice("Focus", "Focus"), new SliderChoice("Hover", "Hover") };
return View();
}
public class SliderChoice
{
public string text { get; set; }
public string id { get; set; }
public SliderChoice(string text, string id) { this.text = text; this.id = id; }
}
}
}
@* 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>
Slider component displays the tooltip to indicate the current value to the user.
In this demo, we have demonstrated Tooltip with Default and Range Slider.
Buttons can be used to increment or decrement the slider value. Buttons can be enabled in Slider using showButtons property
The dragInterval is used to drag both handles using the range bar which is also applicable only to the range slider.
Tooltip position and opening behavior can be customized through the placement and showOn properties from property pane.