The field Selling Price must be a number. MVC

0

I have a field, sale price, which in the model is this way:

  public decimal PrecoVenda { get; set; }

In the ViewModel it looks like this:

[Display(Name = "Preço de Venda")]
    [Required(ErrorMessage = "O campo {0} é obrigatorio.")]
    public decimal PrecoVenda { get; set; }

And here's the View:

 <label asp-for="PrecoVenda" class="col-md-2 control-label"></label>
                <div class="col-md-2">
                    <input asp-for="PrecoVenda" class="form-control" placeholder="Insira o  preço de venda.">
                    <span asp-validation-for="PrecoVenda" class="text-danger"></span>
                </div>

But when you fill in the values, with a comma, for example "0.00" It returns me this message:

  

The field Selling price must be a number.

If I put "25.00", when checking the value is "2500.00"

    
asked by anonymous 03.08.2018 / 20:54

1 answer

0

I was able to solve this by following the tutorial of this link

Install this package:

Install-Package Microsoft.AspNet.Mvc.pt-br

jQuery Valitation is responsible for client-side validation, to globalize it to PT-Br we need to create a new file in the "Scripts" folder named "methods_pt.js" with the following content:

   /*
 * Localized default methods for the jQuery validation plugin.
 * Locale: PT_BR
 */
jQuery.extend(jQuery.validator.methods, {
    date: function (value, element) {
        return this.optional(element) || /^\d\d?\/\d\d?\/\d\d\d?\d?$/.test(value);
    },
    number: function (value, element) {
        return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value);
    }
});

And I call the script on the page that I need last.

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.unobtrusive*",
                    "~/Scripts/jquery.validate*",
                    "~/Scripts/methods_pt.js"));

Hope you can help;)

    
03.08.2018 / 21:55