Example of Custom Format in ASP.NET MVC NumericTextBox Control
This sample demonstrates the custom format functionalities of the Numeric TextBox. The value of Numeric TextBox will be displayed with defined custom format while typing a value or changing a value using up/down buttons in the input boxes.
Enter the distance
Enter the tax
Enter the amount
@Html.UiNumericTextBox("customformat1", new UiNumericTextBoxOptions { Value = 250, Suffix = "km", Min = 0 })
@Html.UiNumericTextBox("customformat2", new UiNumericTextBoxOptions { Value = 25, Suffix = "%", Min = 0, Max = 100 })
@Html.UiNumericTextBox("customformat3", new UiNumericTextBoxOptions { Value = 1025, Prefix = "$", Min = 0 })
<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">Enter the distance</div>
@Html.UiNumericTextBox("customformat1", new UiNumericTextBoxOptions { Value = 250, Suffix = "km", Min = 0 })
<div class="control-label">Enter the tax</div>
@Html.UiNumericTextBox("customformat2", new UiNumericTextBoxOptions { Value = 25, Suffix = "%", Min = 0, Max = 100 })
<div class="control-label">Enter the amount</div>
@Html.UiNumericTextBox("customformat3", new UiNumericTextBoxOptions { Value = 1025, Prefix = "$", Min = 0 })
</div>
</div>
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/CustomFormat.cshtml; it draws what ViewData holds.
public ActionResult CustomFormat()
{
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 provides an option to customize the display format of the numeric value using the format property. It accepts the standard numeric format string and custom numeric format string as specified in MSDN. The formatted value displays when the component is not focused.
In this demo, NumericTextBox control renders with the custom format ###.## km.