Reputation: 4892
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>
Upvotes: 5
Views: 7085
Reputation: 56
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")
Upvotes: 3