JQuery Validation MVC 4 DateTime Globalization

In my class, I have a property:

public virtual DateTime Date { get; set; } 

What does "12/31/2012 12:00:00 AM" by default with the culture set to "en-CA" and "12/31/2012 12:00:00 AM" if the culture is "en" -US " .

JQuery validation works fine in "en-US", but in "en-CA" complains, "Date must be date."

I think the solution uses the jQuery library for globalization. I just don’t know how to do this for ASP.Net General Date Long Time ("G") Format Specifier . Any ideas?

The field Date must be a date

+4
source share
1 answer

The format specifier "Long-term (" G ") format specifier is a combination of a short date (" d ") and a long (" T "), separated by a space."

As long as there is no conditional format specifier ( jQuery for formatting the globalization date ), the same format can be executed (detailed for clarity):

 var shortDate = $.format(@Model.Date, "d"); //Get the short date ...M/d/yyyy var longTime = $.format(@Model.Date, "T"); //Get the long time...h:mm:ss tt var date = shortDate + " " + longTime; //concat the two together. 
0
source

Source: https://habr.com/ru/post/1438029/


All Articles