Movatterモバイル変換


[0]ホーム

URL:


PDF
Edit
Suggest a Feature

    Getting Started with ASP.NET MVC NumericTextBox Control

    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.

    Prerequisites

    System requirements for ASP.NET MVC controls

    Create ASP.NET MVC application with HTML helper

    Install ASP.NET MVC package in the application

    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.

    Add namespace

    AddSyncfusion.EJ2 namespace reference inWeb.config underViews folder.

    <namespaces>    <add namespace="Syncfusion.EJ2"/></namespaces>

    Add stylesheet and script resources

    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.

    Register Syncfusion® script manager

    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>

    Add ASP.NET MVC NumericTextBox control

    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.

    ASP.NET MVC NumericTextBox Control

    Range validation

    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()

    Formatting the value

    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()

    ASP.NET MVC NumericTextBox with Format Value

    Precision of numbers

    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.

    • IfvalidateDecimalOnType 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>

    Restricting Decimal Values in ASP.NET MVC NumericTextBox

    NOTE

    View Sample in GitHub.

    See also

    Help us improve this page

    Please provide additional information

    Please provide additional information

    Please provide additional information

    Please provide additional information

    Please provide additional information
    Please provide additional information
    ×

    [8]ページ先頭

    ©2009-2025 Movatter.jp