Example of Bar in ASP.NET MVC Slider Control
This sample demonstrates the customization of Slider's selection bar. Drag the thumb over the bar for selecting the values between min and max.
Height
Gradient color
Dynamic thumb and selection bar color
@Html.UiSlider("height", new UiSliderOptions { Id = "barHeight", Value = 40, Type = UiSliderType.MinRange, CssClass = "bar-height" })
@Html.UiSlider("gradient", new UiSliderOptions { Id = "barGradient", Values = new double[] { 20, 80 }, Type = UiSliderType.Range, CssClass = "bar-gradient" })
@Html.UiSlider("colors", new UiSliderOptions { Id = "barColor", Value = 50, Type = UiSliderType.MinRange, ColorRange = ranges, Tooltip = new UiSliderTooltip { IsVisible = true } })
<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>
@{
var ranges = new List<UiSliderColorRange>
{
new UiSliderColorRange("#13a10e", 0, 20),
new UiSliderColorRange("#ffc400", 20, 40),
new UiSliderColorRange("#f7630c", 40, 70),
new UiSliderColorRange("#d13438", 70, 100)
};
}
<div class="input-stack">
<div>Height</div>
@Html.UiSlider("height", new UiSliderOptions { Id = "barHeight", Value = 40, Type = UiSliderType.MinRange, CssClass = "bar-height" })
<div>Gradient color</div>
@Html.UiSlider("gradient", new UiSliderOptions { Id = "barGradient", Values = new double[] { 20, 80 }, Type = UiSliderType.Range, CssClass = "bar-gradient" })
<div>Dynamic thumb and selection bar color</div>
@Html.UiSlider("colors", new UiSliderOptions { Id = "barColor", Value = 50, Type = UiSliderType.MinRange, ColorRange = ranges, Tooltip = new UiSliderTooltip { IsVisible = true } })
</div>
<style>
.bar-height .ui-slider-track { top: calc(50% - 5px); height: 10px; border-radius: 5px; }
.bar-gradient .ui-slider-range { background: linear-gradient(to right, #0f6cbd, #8764b8); }
</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/Bar.cshtml; it draws what ViewData holds.
public ActionResult Bar()
{
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 Track using CSS.
- Height - In this sample, Track has been customized to custom height. Here, Thumb has to be adjusted based on the Track height.
- Gradient color - In this sample, Track has been customized with gradient color.
- Dynamic thumb and selection bar color - In this sample, Track and Thumb has been customized to different color for different interval by using created and change Event.