Example of Range Validation in ASP.NET MVC NumericTextBox Control
This sample demonstrates the range validation functionalities of the Numeric TextBox. Change the min, max and step values and click on apply button to change the property values in Numeric TextBox.
Numeric TextBox
Min Value
Max Value
Increment Step
@Html.UiNumericTextBox("range", new UiNumericTextBoxOptions { Value = 15, Min = 10, Max = 100 })
@Html.UiButton(new UiButtonOptions { Id = "buttonApply", Text = "Apply", Color = UiButtonColor.Primary })
<style>
.content-wrapper { width: 90%; max-width: 420px; margin: 0 auto; min-width: 185px; }
.content-wrapper .control-label { padding: 24px 0 10px; font-size: 12px; }
.property-section .property-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.property-section .prop-input { width: 100px; padding: 4px 6px; border: 1px solid var(--ui-input-border); border-radius: var(--ui-radius); background: var(--ui-surface); color: var(--ui-text); font: inherit; }
</style>
<div class="control-section">
<div class="content-wrapper">
<div class="control-label">Numeric TextBox</div>
@Html.UiNumericTextBox("range", new UiNumericTextBoxOptions { Value = 15, Min = 10, Max = 100 })
</div>
</div>
<div class="demo-property-panel property-section" title="Properties">
<div class="property-row"><span>Min Value</span> <input id="min" type="number" class="prop-input" value="10" /></div>
<div class="property-row"><span>Max Value</span> <input id="max" type="number" class="prop-input" value="100" /></div>
<div class="property-row"><span>Increment Step</span> <input id="step" type="number" max="100" min="0" class="prop-input" value="1" /></div>
<div class="property-row"><span></span> @Html.UiButton(new UiButtonOptions { Id = "buttonApply", Text = "Apply", Color = UiButtonColor.Primary })</div>
</div>
<script>
// Syncfusion: Apply gives the numeric textbox the min, the max and the step of the panel
document.getElementById('buttonApply').addEventListener('click', function () {
var box = window.Lumen.get('range');
box.setMin(document.getElementById('min').value);
box.setMax(document.getElementById('max').value);
box.setStep(document.getElementById('step').value);
});
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class NumericTextBoxController : Controller
{
// The page is Views/NumericTextBox/RangeValidation.cshtml; it draws what ViewData holds.
public ActionResult RangeValidation()
{
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>
The NumericTextBox has the options to restrict the input value between a specific range using the min, max, and strictMode properties.
- When you enable the strictMode property, the value will automatically change within a range on passing the out-of-range values.
- When you disable the strictMode property, the NumericTextBox component allows the out-of-range value with the highlighted textbox to indicate the given value is wrong.
In this demo, numeric textbox is restricted between 10 to 100 through the min and max properties. So you can enter only the value between this range.