Aspnet MVC 4 decimal checking

I am having some problems with decimal checking in my application. For example, if I write “14.25” in the text box, which is correct for my culture, this does not allow checking on the client side. Also, if I write 14.25, the point is deleted and 1425 is placed in the property of the entity, and in addition, after SaveChanges, the value stored in the database table is 999.99. Need advice on this. This is related to my other question: https://stackoverflow.com/questions/24186365/set-jquery-culture-once-for-the-entire-aplication-possible/24186535#24186535

EDIT : Added code, it is as simple as this, I thought that I would not be needed, as this should be a common problem.

[DisplayFormat( DataFormatString = "{0:n2}", ApplyFormatInEditMode = true )]
        public decimal Peso { get; set; }

@Html.LabelFor(model => Model.Peso)
<div class="input-control text" data-role="input-control">
    @Html.EditorFor(model => Model.Peso)
    @Html.ValidationMessageFor(model => Model.Peso)
</div>
+4
source share
1 answer

Try using the jQuery globalization plugin from http://github.com/jquery/globalize .

Add the following files to the / scripts folder:

/scripts/globalize.js
/scripts/cultures/globalize.cultures.js
/sctipts/cultures/globalize.culture.de-DE.js

In BundleConfig.cs:

bundles.Add(new ScriptBundle("~/bundles/scripts/globalization").Include(
      "~/Scripts/globalize*",
      "~/Scripts/cultures/globalize*"));

In _Layout.cshtml:

@Scripts.Render("~/bundles/scripts/globalization")
+2
source

Source: https://habr.com/ru/post/1544354/


All Articles