Getting Started
17 Feb 20222 minutes to read
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.
Initialize NumericTextBox control to the Application
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.
Range validation
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();
}
Formatting the value
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.
Precision of numbers
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.
- If
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.
See Also
- How to perform custom validation using FormValidator
- How to customize the UI appearance of the control
- How to customize the spin button’s up and down arrow
- How to customize the step value and hide spin buttons
- How to prevent nullable input in NumericTextBox
- How to maintain trailing zeros in NumericTextBox