0

i've a great problem, i've searched around the web and i have tried several solution (changind modelbinder and culture) but nothing working for me. I have created a model with several fields and this specific field

[Display(Name = "Costo ora/allievo (max € 23,00)")
public decimal CostoAula { get; set; }

Then i have created a controller with views then i have mapped sqlserver.

in the view i have:

<div class="row">
    <div class="form-group col-md-4">
        @Html.LabelFor(model => model.CostoAula, htmlAttributes: new { @class = "control-label col-md-4" })
        <div class="col-md-8">
            @Html.TextBoxFor(model => model.CostoAula, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.CostoAula, "", new { @class = "text-danger" })
        </div>
    </div>
</div>

When I enter 123,00 it says that is not a number. When I enter 123.00 it saves, but in the database I have 12300 because database accept comma as decimal separator.

So i have changed jquery.validate number related row with this:

number: function( value, element ) {
    return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:[,]\d+)?$/.test(value);
},

But it doesn't work. It give me everytime same error!

Please help me! Thank you in advance!

Fabio
  • 7
  • 1
  • 4
  • It needs to be `$.validator.methods.number = function( ...` (you also appear to be missing a `?` in the regex). Refer [MVC/JQuery validation does not accept comma as decimal separator](https://stackoverflow.com/questions/48066208/mvc-jquery-validation-does-not-accept-comma-as-decimal-separator/48247324#48247324) –  Jun 14 '18 at 22:39
  • Thank you Stephen for reply, i have read your link and it says "Note the above script needs to be after the jquery.validate.js script but not wrapped in $(document).ready()", What does it mean? Where do i have to put it? Thank you – Fabio Jun 15 '18 at 15:27
  • Just as it says. I do not know what the structure of you page (are you scripts in the layout, are you using sections etc) so I cannot tell you –  Jun 16 '18 at 05:27
  • Thank you Stephen, i can try to explain better, What mean "the above script needs to be after...? jquery.validate.js is a file with scripts inside; where do i have to put this code $.validator.methods.number = function( ... ? After what? Thank you – Fabio Jun 16 '18 at 12:58

0 Answers0