2013-07-02 30 views
1

我使用這個jQuery插件選擇時間:http://jonthornton.github.io/jquery-timepicker/jQuery的時間選擇器和MVC 4驗證 - 現場必須是日期

我初始化我timepicker這樣的:

$('#scheduletime').timepicker({ 'scrollDefaultNow': true, 'timeFormat': 'h:i A' }); 

導致時間顯示在以下格式:

08:00 AM 

我使用MVC客戶端驗證,和我的模型看起來像這樣:

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:hh:mm tt}")] 
public DateTime? ScheduleTime { get; set; } 

我的問題是,我收到了客戶端驗證錯誤:

The field ScheduleTime must be a date.

什麼錯?字符串驗證格式似乎是正確的,但它不起作用。

+0

是DisplayFormat的唯一數據註釋屬性你有你的ScheduleTime財產? – ataravati

+0

@ataravati我也有[顯示(名稱=「計劃時間」)] – Leigh

回答

3

使用數據類型屬性,在產品型號如下:

[DataType(DataType.Time)] 
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:hh:mm tt}")] 
[Display(Name = "Schedule Time")] 
public DateTime? ScheduleTime { get; set; } 
相關問題