4

在我的課堂我的財產:jQuery驗證全球化MVC 4日期時間

public virtual DateTime Date { get; set; } 

它默認設置爲「en-CA的文化呈現 「31/12/2012 12:00:00 AM」 「和」12/31/2012 12:00:00 AM「,如果文化是」en-US「的話。

jQuery的驗證工作正常「EN-US」,但在「EN-CA」抱怨「這個領域日期必須是日期」。

我認爲解決的辦法是使用jQuery全球化庫。我只是不知道如何去做這個"General Date Long Time ("G") Format Specifier" ASP.Net呈現。有任何想法嗎?

The field Date must be a date

+0

你是如何設置的文化 「EN-US」,「EN-CA 「? –

+0

感謝您的關注@LenielMacaferi。在web.config'<全球化文化= 「EN-CA」 的UICulture = 「自動」/>'。 –

回答

0

General Long time ("G") Format Specifier格式指示符「表示短日期的組合(」 d「)和長的時間(」 T「)的圖案,由空格分隔」。

雖然沒有一個equivelant格式說明(jQuery Globalize Date Formatting)相同的格式可通過(詳細爲清楚起見)來完成:

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.