0

I am developing a small mvc applicacion and I am facing a problem with the datetime and decimal properties of my entities, specially when creating or editing using the scaffolded views/controllers. I am using VS2017 in a machine with English (United States) regional settings.

This is my example class

public partial class Data
{
    public int Id { get; set; }
    public System.DateTime DateProp { get; set; }
    public decimal DecProp { get; set; }
}

When I run the code everything works fine. I get to see and edit the values properly.

Index listing values

Edit values

Now if I change the machine region and language settings to say, Spanish (Argentina) I do get to see the changes both in the listings and the edit pages

Listing Spanish format

But when I want to either create or edit an existing entity I get validations from both fields.

Validation errors for datetime and decimal

I suspect it is the javascript validation. What can I do to either the classes/controllers/views to make an application that will work. No matter the machine's regional settings?

Any help will be greatly appreciated!

  • You need to reconfigure the `$.validator` (or use a plugin such as [globalize.js](https://github.com/globalizejs/globalize) –  May 13 '18 at 22:32
  • For an example for the numeric value, refer [this answer](https://stackoverflow.com/questions/48066208/mvc-jquery-validation-does-not-accept-comma-as-decimal-separator/48247324#48247324). For an example for a date, refer [this answer](https://stackoverflow.com/questions/39677035/date-of-birth-validation-keeps-showing/39682410#39682410) –  May 13 '18 at 23:10
  • Thanks @StephenMuecke! I think I have now a better understanding of what's going on. I'd like to use the globalize.js pluging but js is not my forte. Could you explain me how to add it to the vs project and test it out? Sorry for the inconvenience. – Edward Sanxs May 14 '18 at 01:51
  • Refer [this article](https://blog.johnnyreilly.com/2012/09/globalize-and-jquery-validate.html) fro an example –  May 14 '18 at 01:56
  • Thanks @StephenMuecke. I followed his instructions and I have two further questions. 1) The author mentions specialized culture js files.. like scripts/globalize/globalize.culture.en-GB.js for instance. The nutget package didn't installed those for me. Where can it get them? [link](https://i.imgur.com/SHSpC9L.png) 2) After that should I still have to edit or add any js? like editing the validators? – Edward Sanxs May 14 '18 at 02:44

0 Answers0