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.

6
  • check it stackoverflow.com/questions/32236013/… Commented Jan 22, 2018 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.. Commented Jan 22, 2018 at 16:55
  • You need t reconfigure the $.validator which by default validates numbers with the decimal separator as a . (dot) Commented Jan 22, 2018 at 21:16
  • @StephenMuecke ok, seems good, but how I do it in ASP.Net MVC 5 ?! Commented Jan 22, 2018 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) Commented Jan 22, 2018 at 21:39

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Both are set in french (server and my browser) and the regional settings are set to "," as separator for currency.
In German we use the same decimal seperator. To find out what the real problem is can u please open this fiddle: jsfiddle.net/MeikelLP/x9x3r7bm And tell me if , or . works. In my case only , worked (german decimal seperator).
It does NOT use the browser language. It use US formats

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.