Example of Thumb in ASP.NET MVC Slider Control
This sample demonstrates the customization of Slider's Thumb. Drag the thumb over the bar for selecting the values between min and max.
@Html.UiSlider("square", new UiSliderOptions { Id = "thumbSquare", Value = 30, CssClass = "thumb-square" })
@Html.UiSlider("circle", new UiSliderOptions { Id = "thumbCircle", Value = 50, Type = UiSliderType.MinRange, CssClass = "thumb-circle" })
@Html.UiSlider("oval", new UiSliderOptions { Id = "thumbOval", Values = new double[] { 30, 70 }, Type = UiSliderType.Range, CssClass = "thumb-oval" })
@Html.UiSlider("image", new UiSliderOptions { Id = "thumbImage", Value = 60, Type = UiSliderType.MinRange, CssClass = "thumb-image" })
<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 slider-thumbs">
<div>Square</div>
@Html.UiSlider("square", new UiSliderOptions { Id = "thumbSquare", Value = 30, CssClass = "thumb-square" })
<div>Circle</div>
@Html.UiSlider("circle", new UiSliderOptions { Id = "thumbCircle", Value = 50, Type = UiSliderType.MinRange, CssClass = "thumb-circle" })
<div>Oval</div>
@Html.UiSlider("oval", new UiSliderOptions { Id = "thumbOval", Values = new double[] { 30, 70 }, Type = UiSliderType.Range, CssClass = "thumb-oval" })
<div>Custom image</div>
@Html.UiSlider("image", new UiSliderOptions { Id = "thumbImage", Value = 60, Type = UiSliderType.MinRange, CssClass = "thumb-image" })
</div>
<style>
.thumb-square .ui-slider-handle { border-radius: 0; box-shadow: none; }
.thumb-circle .ui-slider-handle { background: var(--ui-surface); box-shadow: 0 0 0 3px var(--ui-accent); }
.thumb-oval { --ui-slider-handle: 18px; }
.thumb-oval .ui-slider-handle { width: 34px; margin-left: -17px; border-radius: 9px; }
.thumb-image { --ui-slider-handle: 28px; }
.thumb-image .ui-slider-handle {
background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23f7b500' d='M12 2l2.9 6.6 7.1.6-5.4 4.7 1.6 7.1L12 17.3 5.8 21l1.6-7.1L2 9.2l7.1-.6z'/%3E%3C/svg%3E") center / 20px no-repeat;
box-shadow: 0 0 0 1px var(--ui-input-border);
}
</style>
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/Thumb.cshtml; it draws what ViewData holds.
public ActionResult Thumb()
{
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 Thumb by changing CSS.
- Square - In this sample, Thumb has been customized to Square shape.
- Circle - In this sample, Thumb has been customized to Circle shape.
- Oval - In this sample, Thumb has been customized to Oval shape.
- Custom image - In this sample, Thumb has been replaced with custom image.