Example of Adornments in ASP.NET MVC NumericTextBox Control
This example highlights adornment support in the Syncfusion Numeric TextBox. Adornments let you place custom elements before or after the input by using the prependTemplate and appendTemplate properties of Numeric Textbox such as currency symbols, unit labels, dropdowns, or action icons to provide context, trigger actions, and improve input clarity and efficiency.
@Html.UiNumericTextBox("prepend", new UiNumericTextBoxOptions { Value = 1, Label = "Enter the price", FloatLabelType = UiFloatLabelType.Auto, PrependTemplate = "#numMenu", OnChange = "onPriceChange" })
@Html.UiNumericTextBox("append", new UiNumericTextBoxOptions { Value = 5, Label = "Enter the kg", FloatLabelType = UiFloatLabelType.Auto, AppendTemplate = "#numKg", OnChange = "onKgChange" })
@Html.UiNumericTextBox("icontemplate", new UiNumericTextBoxOptions { Value = 10, Label = "Enter the Number", FloatLabelType = UiFloatLabelType.Auto, ShowSpinButton = false, PrependTemplate = "#numReset", AppendTemplate = "#numSteps" })
<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; }
.adorn-row { margin: 25px 0; }
.e-adornments .e-icons { cursor: pointer; }
</style>
<template id="numMenu"><span id="menu" class="e-icons e-menu" title="Menu"></span><span class="ui-input-separator"></span><span id="search" class="e-icons e-search" title="Search"></span><span class="ui-input-separator"></span></template>
<template id="numKg"><span>kg</span></template>
<template id="numReset"><span id="reset" class="e-icons e-reset" title="Reset"></span><span class="ui-input-separator"></span></template>
<template id="numSteps"><span class="ui-input-separator"></span><span id="subract" class="e-icons e-horizontal-line"></span><span class="ui-input-separator"></span><span id="plus" class="e-icons e-plus"></span></template>
<div class="control-section">
<div class="content-wrapper e-adornments">
<div class="adorn-row">@Html.UiNumericTextBox("prepend", new UiNumericTextBoxOptions { Value = 1, Label = "Enter the price", FloatLabelType = UiFloatLabelType.Auto, PrependTemplate = "#numMenu", OnChange = "onPriceChange" })</div>
<div class="adorn-row">@Html.UiNumericTextBox("append", new UiNumericTextBoxOptions { Value = 5, Label = "Enter the kg", FloatLabelType = UiFloatLabelType.Auto, AppendTemplate = "#numKg", OnChange = "onKgChange" })</div>
<div class="adorn-row">@Html.UiNumericTextBox("icontemplate", new UiNumericTextBoxOptions { Value = 10, Label = "Enter the Number", FloatLabelType = UiFloatLabelType.Auto, ShowSpinButton = false, PrependTemplate = "#numReset", AppendTemplate = "#numSteps" })</div>
</div>
</div>
<script>
// Syncfusion: the price and the kilograms follow each other (5 per kg); the icons of the last box reset it and step it down and up
function numeric(id) { return window.Lumen.get(id); }
function onPriceChange(value) { numeric('append').setValue(value * 5); }
function onKgChange(value) { numeric('prepend').setValue(value / 5); }
document.addEventListener('click', function (e) {
var icon = e.target.closest ? e.target.closest('#reset, #subract, #plus') : null;
if (!icon) { return; }
var box = numeric('icontemplate');
var now = box.getValue() || 0;
box.setValue(icon.id === 'reset' ? 0 : icon.id === 'plus' ? now + 1 : now - 1);
});
</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/Adornments.cshtml; it draws what ViewData holds.
public ActionResult Adornments()
{
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>
This example highlights adornment support in the Syncfusion Numeric TextBox. Adornments let you place custom elements before or after the input by using the prependTemplate and appendTemplate properties of Numeric Textbox such as currency symbols, unit labels or action icons to provide context, trigger actions, and improve input clarity and efficiency.