5

I'm facing some problems validating decimals in my application. For example, if I write "14,25" into the textbox, which is correct for my culture, it fails client side validation. Also if I write 14.25 the dot is removed and 1425 is placed in the entity property and moreover, after SaveChanges the value saved to database table is 999,99. Need advide on this issue. This is related to my other question here: https://stackoverflow.com/questions/24186365/set-jquery-culture-once-for-the-entire-aplication-possible/24186535#24186535

EDIT: Code added, it is as simple as this, I thought I wouldn't be necessary as this have to be a common issue.

[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>
1
  • 1
    showing some code...???? Commented Jun 12, 2014 at 15:28

1 Answer 1

3

Try using jQuery's Globalization plugin from http://github.com/jquery/globalize.

Add following files to /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")
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks i'm goint to tray it, does Globalization have an NuGet package?
I cannot find folder culture with cultures js files, seems that they ware removed from the project?
Create those folders if they don't exist. I don't think it has a NuGet Package.
Google file names, you will find them and will be able to download/save them.
Here you go for the Nuget Package: nuget.org or Install-Package jquery-globalize
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.