0

I found an old solution to my problem but it's seem they doesn't work in ASP.NET MVC 5. I want a view (automatically generated) from my ASP.NET MVC website that accepts a price with a comma.

My model class is

public class Alert
{
    public int AlertId { get; set; }
    [ForeignKey("CieId")]
    public Cie AlertCie { get; set; }
    public int CieId { get; set; }
    [ForeignKey("PortfolioId")]
    [Display(Name = "Threshold Price")]
    [DataType(DataType.Currency)]
    public decimal Price { get; set; }
}

The view error message is the following:

MVC View EF

I run my site web with this web.config entry :

culture="fr-CA" uiCulture="fr-CA"

The issue is at the view level, I'm unable to create a new entry. I think the JS script blocks it.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
oL.
  • 196
  • 5
  • 15
  • check it https://stackoverflow.com/questions/32236013/asp-net-mvc-binding-decimal-value – Roman Kiyashev Jan 22 '18 at 16:47
  • My code accepts coma for float format. The view is able to display them correcty to. I just not able to fill out the view form.. – oL. Jan 22 '18 at 16:55
  • You need t reconfigure the `$.validator` which by default validates numbers with the decimal separator as a `.` (dot) –  Jan 22 '18 at 21:16
  • @StephenMuecke ok, seems good, but how I do it in ASP.Net MVC 5 ?! – oL. Jan 22 '18 at 21:35
  • See the dupe - its the same for all versions - just add the `$.validator.methods.number = function (value, element) { ...` to override the default behavior (I will also see if I can fine a good link for using the globalize plugin) –  Jan 22 '18 at 21:39
  • Refer also [MVC 3 jQuery Validation/globalizing of number/decimal field](https://stackoverflow.com/questions/5199835/mvc-3-jquery-validation-globalizing-of-number-decimal-field) for using the [globalize](https://github.com/globalizejs/globalize) plugin –  Jan 22 '18 at 21:45

1 Answers1

0

The client side validation comes from jquery.validation (Default). It uses the browser language not the server language.

So you have to make the client use your server language.

Meikel
  • 314
  • 2
  • 12
  • Both are set in french (server and my browser) and the regional settings are set to "," as separator for currency. – oL. Jan 22 '18 at 18:04
  • In German we use the same decimal seperator. To find out what the real problem is can u please open this fiddle: https://jsfiddle.net/MeikelLP/x9x3r7bm/ And tell me if , or . works. In my case only , worked (german decimal seperator). – Meikel Jan 22 '18 at 21:47
  • It does NOT use the browser language. It use US formats –  Jan 23 '18 at 09:16