9 Dec 20244 minutes to read
This section briefly explains about how to includeASP.NET MVC NumericTextBox control in your ASP.NET MVC application using Visual Studio.
System requirements for ASP.NET MVC controls
To addASP.NET MVC
controls in the application, open the NuGet package manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), search forSyncfusion.EJ2.MVC5 and then install it.
Install-PackageSyncfusion.EJ2.MVC5-Version31.1.17
NOTE
Syncfusion® ASP.NET MVC controls are available innuget.org. Refer toNuGet packages topic to learn more about installing NuGet packages in various OS environments. The Syncfusion.EJ2.MVC5 NuGet package has dependencies,Newtonsoft.Json for JSON serialization andSyncfusion.Licensing for validating Syncfusion® license key.
AddSyncfusion.EJ2 namespace reference inWeb.config
underViews
folder.
<namespaces> <add namespace="Syncfusion.EJ2"/></namespaces>
Here, the theme and script is referred using CDN inside the<head>
of~/Pages/Shared/_Layout.cshtml
file as follows,
<head> ...<!-- Syncfusion ASP.NET MVC controls styles --><linkrel="stylesheet"href="https://cdn.syncfusion.com/ej2/31.1.17/fluent.css"/><!-- Syncfusion ASP.NET MVC controls scripts --><scriptsrc="https://cdn.syncfusion.com/ej2/31.1.17/dist/ej2.min.js"></script></head>
NOTE
Checkout theThemes topic to learn different ways (CDN, NPM package, andCRG) to refer styles in ASP.NET MVC application, and to have the expected appearance for Syncfusion® ASP.NET MVC controls. Checkout theAdding Script Reference topic to learn different approaches for adding script references in your ASP.NET MVC application.
Also, register the script managerEJS().ScriptManager()
at the end of<body>
in the~/Pages/Shared/_Layout.cshtml
file as follows.
<body>...<!-- Syncfusion ASP.NET MVC Script Manager --> @Html.EJS().ScriptManager()</body>
Now, add the Syncfusion® ASP.NET MVC NumericTextBox control in~/Views/Home/Index.cshtml
page.
@Html.EJS().NumericTextBox("numeric").Value(10).Render()
PressCtrl+F5 (Windows) or⌘+F5 (macOS) to run the app. Then, the Syncfusion® ASP.NET MVC NumericTextBox control will be rendered in the default web browser.
You can set the minimum and maximum range of values in the NumericTextBox using theMin andMax properties, so the numeric value should be in the min and max range.
The validation behavior depends on theStrictMode property.
@Html.EJS().NumericTextBox("numeric").Value(16).Min(10).Max(20).Step(2).Render()
User can set the format of the NumericTextBox control usingFormat property. The value will be displayed in the specified format, when the control is in focused out state. For more information about formatting the value, refer to thislink.
The below example demonstrates format the value by using currency format valuec2
.
@Html.EJS().NumericTextBox("numeric").Format("c2").Value(10).Render()
You can restrict the number of decimals to be entered in the NumericTextBox by using theDecimals andValidateDecimalOnType 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.<divid='container'><divclass='wrap'> @Html.EJS().NumericTextBox("strict").Format("n3").Value(10).ValidateDecimalOnType(true).Decimals(3).Placeholder("ValidateDecimalOnType Enabled").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Auto).Render()</div><divclass='wrap'> @Html.EJS().NumericTextBox("allow").Format("n3").Value(10).Decimals(3).Placeholder("ValidateDecimalOnType Disabled").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Auto).Render()</div></div>
NOTE