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.
什麼錯?字符串驗證格式似乎是正確的,但它不起作用。
是DisplayFormat的唯一數據註釋屬性你有你的ScheduleTime財產? – ataravati
@ataravati我也有[顯示(名稱=「計劃時間」)] – Leigh