Example of Tooltip in ASP.NET MVC Slider Control
This sample demonstrates the customization of Slider's Tooltip. Drag the thumb over the bar for selecting the values between min and max.
After the track, currency
Before the track, percentage
Background color
Color and text: a time of day (minutes after 06:00, in steps of 30)
@Html.UiSlider("customTip", new UiSliderOptions { Min = 0, Max = 1000, Step = 10, Value = 350, Tooltip = new UiSliderTooltip { IsVisible = true, ShowOn = UiSliderTooltipShowOn.Always, Placement = UiSliderPlacement.After, Format = "C0" } })
@Html.UiSlider("customTipBefore", new UiSliderOptions { Min = 0, Max = 1, Step = 0.05, Value = 0.25, Tooltip = new UiSliderTooltip { IsVisible = true, ShowOn = UiSliderTooltipShowOn.Always, Placement = UiSliderPlacement.Before, Format = "P0" } })
@Html.UiSlider("customTipColor", new UiSliderOptions { Value = 60, CssClass = "tip-blue", Tooltip = new UiSliderTooltip { IsVisible = true, ShowOn = UiSliderTooltipShowOn.Always } })
@Html.UiSlider("customTipTime", new UiSliderOptions { Min = 0, Max = 720, Step = 30, Value = 240, CssClass = "tip-green", Ticks = new UiSliderTicks { Placement = UiSliderPlacement.After, LargeStep = 180, SmallStep = 30, ShowSmallTicks = true }, Tooltip = new UiSliderTooltip { IsVisible = true, ShowOn = UiSliderTooltipShowOn.Always }, OnTooltipChange = "SliderSamples.time", OnRenderingTicks = "SliderSamples.time" })
<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>
<div class="input-stack">
<div>After the track, currency</div>
@Html.UiSlider("customTip", new UiSliderOptions { Min = 0, Max = 1000, Step = 10, Value = 350, Tooltip = new UiSliderTooltip { IsVisible = true, ShowOn = UiSliderTooltipShowOn.Always, Placement = UiSliderPlacement.After, Format = "C0" } })
<div>Before the track, percentage</div>
@Html.UiSlider("customTipBefore", new UiSliderOptions { Min = 0, Max = 1, Step = 0.05, Value = 0.25, Tooltip = new UiSliderTooltip { IsVisible = true, ShowOn = UiSliderTooltipShowOn.Always, Placement = UiSliderPlacement.Before, Format = "P0" } })
<div>Background color</div>
@Html.UiSlider("customTipColor", new UiSliderOptions { Value = 60, CssClass = "tip-blue", Tooltip = new UiSliderTooltip { IsVisible = true, ShowOn = UiSliderTooltipShowOn.Always } })
<div>Color and text: a time of day (minutes after 06:00, in steps of 30)</div>
@Html.UiSlider("customTipTime", new UiSliderOptions { Min = 0, Max = 720, Step = 30, Value = 240, CssClass = "tip-green", Ticks = new UiSliderTicks { Placement = UiSliderPlacement.After, LargeStep = 180, SmallStep = 30, ShowSmallTicks = true }, Tooltip = new UiSliderTooltip { IsVisible = true, ShowOn = UiSliderTooltipShowOn.Always }, OnTooltipChange = "SliderSamples.time", OnRenderingTicks = "SliderSamples.time" })
</div>
<style>
.tip-blue .ui-slider-tooltip { background: #0f6cbd; color: #fff; }
.tip-green .ui-slider-tooltip { background: #107c10; color: #fff; font-weight: 600; }
</style>
<script>
// Syncfusion: the tooltip text is a time of day (minutes after 06:00)
var SliderSamples = {
time: function (args) {
var minutes = 6 * 60 + Number(args.value);
var h = Math.floor(minutes / 60) % 24, m = minutes % 60;
args.text = (h % 12 === 0 ? 12 : h % 12) + ':' + (m < 10 ? '0' : '') + m + ' ' + (h < 12 ? 'AM' : 'PM');
}
};
</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/CustomTooltip.cshtml; it draws what ViewData holds.
public ActionResult CustomTooltip()
{
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>
In this demo, we have demonstrated the following customization of Tooltip using CSS.
- Background color - In this sample, Tooltip has been customized to custom color.
- Color and text - In this sample, Tooltip and its content has been customized to custom color.