Example of API in ASP.NET MVC Slider Control
This sample demonstrates the customization of Slider component by using its properties from property pane. Select any combination of properties from property pane to customize Slider component.
Value
Min
Max
Step
Show Buttons
Disabled
Readonly
Vertical Orientation
@Html.UiSlider("slider", new UiSliderOptions { Value = 30, Min = 0, Max = 100, Type = UiSliderType.MinRange, OnInput = "onSliderChange", Tooltip = new UiSliderTooltip { IsVisible = true, Placement = UiSliderPlacement.Before, ShowOn = UiSliderTooltipShowOn.Always } })
@Html.UiNumericTextBox("value", new UiNumericTextBoxOptions { Value = 30, Step = 1, Format = "N0", Width = "100px", OnChange = "onValueChange" })
@Html.UiNumericTextBox("min", new UiNumericTextBoxOptions { Value = 0, Step = 1, Format = "N0", Width = "100px", OnChange = "onMinChange" })
@Html.UiNumericTextBox("max", new UiNumericTextBoxOptions { Value = 100, Step = 1, Format = "N0", Width = "100px", OnChange = "onMaxChange" })
@Html.UiNumericTextBox("step", new UiNumericTextBoxOptions { Value = 1, Step = 1, Format = "N0", Width = "100px", OnChange = "onStepChange" })
@Html.UiCheckBox("button", false, new UiCheckBoxOptions { Id = "button", OnChange = "onShowButtonChange" })
@Html.UiCheckBox("disabled", false, new UiCheckBoxOptions { Id = "disabled", OnChange = "onDisableChange" })
@Html.UiCheckBox("readOnly", false, new UiCheckBoxOptions { Id = "readOnly", OnChange = "onReadOnlyeChange" })
@Html.UiCheckBox("orientation", false, new UiCheckBoxOptions { Id = "orientation", OnChange = "onOrientationChange" })
<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; }
#all-option-sample .sliderwrap { margin-top: 90px; }
</style>
<div class="control-section" id="all-option-sample">
<div class="content-wrapper">
<div class="sliderwrap">
@Html.UiSlider("slider", new UiSliderOptions { Value = 30, Min = 0, Max = 100, Type = UiSliderType.MinRange, OnInput = "onSliderChange", Tooltip = new UiSliderTooltip { IsVisible = true, Placement = UiSliderPlacement.Before, ShowOn = UiSliderTooltipShowOn.Always } })
</div>
</div>
</div>
<div class="demo-property-panel property-section" id="all-option-table" title="Properties">
<div class="property-row"><span>Value</span> @Html.UiNumericTextBox("value", new UiNumericTextBoxOptions { Value = 30, Step = 1, Format = "N0", Width = "100px", OnChange = "onValueChange" })</div>
<div class="property-row"><span>Min</span> @Html.UiNumericTextBox("min", new UiNumericTextBoxOptions { Value = 0, Step = 1, Format = "N0", Width = "100px", OnChange = "onMinChange" })</div>
<div class="property-row"><span>Max</span> @Html.UiNumericTextBox("max", new UiNumericTextBoxOptions { Value = 100, Step = 1, Format = "N0", Width = "100px", OnChange = "onMaxChange" })</div>
<div class="property-row"><span>Step</span> @Html.UiNumericTextBox("step", new UiNumericTextBoxOptions { Value = 1, Step = 1, Format = "N0", Width = "100px", OnChange = "onStepChange" })</div>
<div class="property-row"><span>Show Buttons</span> @Html.UiCheckBox("button", false, new UiCheckBoxOptions { Id = "button", OnChange = "onShowButtonChange" })</div>
<div class="property-row"><span>Disabled</span> @Html.UiCheckBox("disabled", false, new UiCheckBoxOptions { Id = "disabled", OnChange = "onDisableChange" })</div>
<div class="property-row"><span>Readonly</span> @Html.UiCheckBox("readOnly", false, new UiCheckBoxOptions { Id = "readOnly", OnChange = "onReadOnlyeChange" })</div>
<div class="property-row"><span>Vertical Orientation</span> @Html.UiCheckBox("orientation", false, new UiCheckBoxOptions { Id = "orientation", OnChange = "onOrientationChange" })</div>
</div>
<script>
// Syncfusion: the panel sets the value, the range, the step, the buttons, the states and the orientation of the slider
function slider() { return window.Lumen.get('slider'); }
function onSliderChange(value) { window.Lumen.get('value').setValue(value); }
function onValueChange(value) { slider().setValue(value); }
function onMinChange(value) { slider().setMin(value); }
function onMaxChange(value) { slider().setMax(value); }
function onStepChange(value) { slider().setStep(value); }
function onShowButtonChange(checked) { slider().setShowButtons(checked); }
function onDisableChange(checked) { slider()[checked ? 'disable' : 'enable'](); }
function onReadOnlyeChange(checked) { slider().setReadOnly(checked); }
function onOrientationChange(checked) { slider().setVertical(checked); }
</script>
<script>
(function (window, document) {
'use strict';
document.querySelector('.input-actions').addEventListener('click', function (event) {
var action = event.target.getAttribute('data-input-action');
var control = window.Lumen.get('inputApi');
if (!action || !control) { return; }
if (action === 'set') { control.setValue(75); }
else if (action === 'state') { window.InputSampleLog('Value present: ' + (control.getValue() !== null)); return; }
else if (action === 'enabled') { control[control.isEnabled() ? 'disable' : 'enable'](); }
else if (action === 'refresh') { control.refresh(); }
else if (action === 'focus') { control.focus(); }
window.InputSampleLog('API action: ' + action);
});
})(window, document);
</script>
using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class RangeSliderController : Controller
{
// The page is Views/RangeSlider/API.cshtml; it draws what ViewData holds.
public ActionResult API()
{
return View();
}
private ActionResult Show(string method)
{
InputSample sample = (InputSample)ViewBag.InputSample;
// A sample keeps its data in a Prepare<Page> method (InputsDemoController.Samples.cs); it puts what the page reads in ViewData.
string page = sample.Source.Substring(sample.Source.LastIndexOf('_') + 1);
System.Reflection.MethodInfo prepare = GetType().GetMethod(method + page, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (prepare != null) { prepare.Invoke(this, null); }
return View("PreparedSample", ViewData.Model);
}
}
}
@* 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>
@* Inputss with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
In this demo, default slider is rendered with minimal configuration.
This sample can be customized further with the combination of Slider properties from the property pane. For example,
- Min, max, value and Steps can be changed from the property pane.
- Ticks can be enabled by selecting the ticks placement from the property pane.
- Tooltip can be enabled by checking Show tooltip checkbox from property pane.
- Vertical orientation can be enabled by checking vertical orientation from property pane and so on.