Example of Ticks in ASP.NET MVC Slider Control
This sample demonstrates the customization of Slider's Tick. Drag the thumb over the bar for selecting the values between min and max.
Currency ticks on both sides
Large steps only
Dynamic ticks color: the ticks up to the handle take its colour
Ticks with legends
@Html.UiSlider("customTicks", new UiSliderOptions { Min = 0, Max = 1000, Step = 50, Value = 400, Ticks = new UiSliderTicks { Placement = UiSliderPlacement.Both, LargeStep = 250, SmallStep = 50, ShowSmallTicks = true, Format = "C0" } })
@Html.UiSlider("customTicksLarge", new UiSliderOptions { Type = UiSliderType.MinRange, Value = 60, Ticks = new UiSliderTicks { Placement = UiSliderPlacement.Before, LargeStep = 25, ShowSmallTicks = false } })
@Html.UiSlider("customTicksColor", new UiSliderOptions { Type = UiSliderType.MinRange, Value = 40, Ticks = new UiSliderTicks { Placement = UiSliderPlacement.After, LargeStep = 20, SmallStep = 10, ShowSmallTicks = true }, OnInput = "SliderSamples.tickColor", OnChange = "SliderSamples.tickColor", OnCreated = "SliderSamples.tickColor" })
@Html.UiSlider("customTicksLegend", new UiSliderOptions { Type = UiSliderType.MinRange, Value = 50, Ticks = new UiSliderTicks { Placement = UiSliderPlacement.After, LargeStep = 25, SmallStep = 25, ShowSmallTicks = false }, OnRenderingTicks = "SliderSamples.legend" })
<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>Currency ticks on both sides</div>
@Html.UiSlider("customTicks", new UiSliderOptions { Min = 0, Max = 1000, Step = 50, Value = 400, Ticks = new UiSliderTicks { Placement = UiSliderPlacement.Both, LargeStep = 250, SmallStep = 50, ShowSmallTicks = true, Format = "C0" } })
<div>Large steps only</div>
@Html.UiSlider("customTicksLarge", new UiSliderOptions { Type = UiSliderType.MinRange, Value = 60, Ticks = new UiSliderTicks { Placement = UiSliderPlacement.Before, LargeStep = 25, ShowSmallTicks = false } })
<div>Dynamic ticks color: the ticks up to the handle take its colour</div>
@Html.UiSlider("customTicksColor", new UiSliderOptions { Type = UiSliderType.MinRange, Value = 40, Ticks = new UiSliderTicks { Placement = UiSliderPlacement.After, LargeStep = 20, SmallStep = 10, ShowSmallTicks = true }, OnInput = "SliderSamples.tickColor", OnChange = "SliderSamples.tickColor", OnCreated = "SliderSamples.tickColor" })
<div>Ticks with legends</div>
@Html.UiSlider("customTicksLegend", new UiSliderOptions { Type = UiSliderType.MinRange, Value = 50, Ticks = new UiSliderTicks { Placement = UiSliderPlacement.After, LargeStep = 25, SmallStep = 25, ShowSmallTicks = false }, OnRenderingTicks = "SliderSamples.legend" })
</div>
<script>
// Syncfusion: the ticks up to the handle take a colour, and the ticks get a legend
var SliderSamples = {
tickColor: function () {
var slider = window.Lumen.get('customTicksColor');
var root = document.getElementById('customTicksColor').closest('.ui-slider');
if (!slider || !root) { return; }
var now = slider.getValue();
[].forEach.call(root.querySelectorAll('.ui-slider-tick-large'), function (tick, i) { tick.style.background = i * 20 <= now ? '#0f6cbd' : ''; });
},
legend: function (args) { args.text = args.value <= 0 ? 'Low' : args.value >= 100 ? 'High' : args.value === 50 ? 'Medium' : ''; }
};
</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/CustomTicks.cshtml; it draws what ViewData holds.
public ActionResult CustomTicks()
{
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 Ticks using CSS.
- Dynamic ticks color - In this sample, Ticks has been customized to different colors by adding icon at each Ticks.
- Ticks with legends - In this sample, Track has been formatted to display custom text using renderingTicks and renderedTicks events.