This section briefly explains about how to include a simple NumericTextBox in your ASP.NET MVC application. You can refer ASP.NET MVC Getting Started documentation page for introduction part part of the system requirements and configure the common specifications.
NumericTextBox component can be rendered by using the EJS().NumericTextBox()
tag helper in ASP.NET MVC application. Add the below simple code to your index.cshtml
page which is available within the Views/Home
folder, to initialize the NumericTextBox.
The following example shows a basic NumericTextBox component.
@Html.EJS().NumericTextBox("numeric").Value(10).Render()
public ActionResult Demo()
{
return View();
}
Running the above code will display the basic NumericTextBox on the browser.
Output be like the below.
You can set the minimum and maximum range of values in the NumericTextBox using the min and max properties, so the numeric value should be in the min and max range.
The validation behavior depends on the strictMode property.
The below example demonstrates range validation.
@Html.EJS().NumericTextBox("numeric").Value(16).Min(10).Max(20).Step(2).Render()
public ActionResult Range()
{
return View();
}
User can set the format of the NumericTextBox component using format property. The value will be displayed in the specified format, when the component is in focused out state. For more information about formatting the value, refer to this link.
The below example demonstrates format the value by using currency format value c2
.
@Html.EJS().NumericTextBox("numeric").Format("c2").Value(10).Render()
public ActionResult Format()
{
return View();
}
Output be like the below.
You can restrict the number of decimals to be entered in the NumericTextBox by using the decimals and validateDecimalOnType properties. So, you can’t enter the number whose precision is greater than the mentioned decimals.
validateDecimalOnType
is false, number of decimals will not be restricted.
Else, number of decimals will be restricted while typing in the NumericTextBox.<div id='container'>
<div class='wrap'>
@Html.EJS().NumericTextBox("strict").Format("n3").Value(10).ValidateDecimalOnType(true).Decimals(3).Placeholder("ValidateDecimalOnType enabled").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Auto).Render()
</div>
<div class='wrap'>
@Html.EJS().NumericTextBox("allow").Format("n3").Value(10).Decimals(3).Placeholder("ValidateDecimalOnType enabled").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Auto).Render()
</div>
</div>
public ActionResult Precision()
{
return View();
}
Output be like the below.