在我的模型,我有:ASP.NET MVC3:顯示格式正確日期與jQuery的DatePicker和editorFor/TextBoxFor
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime StartDate { get; set; }
不幸的是,它僅適用於EditorFor,但我不能指定EditorFor類,以啓用Jquery Datetime選取器,因爲沒有htmlAttributes
參數。
@Html.EditorFor(model => model.StartDate)
@Html.TextBoxFor(model => model.StartDate, new { @class = "datePicker", @readonly = "readonly" })
所以第一個只顯示日期,但沒有datepicker。 第二個顯示時間也是00:00,但有一個datetimepicker。
注意:不只是說,使用model.StartDate.ToString("mm/DD/yyyy")
。這是行不通的。
如何設置日期。但有一個時間選擇器並只讀,所以我不能在其中輸入任何數字。
我對MVC級解決方案感興趣。我最終採用了標準的html輸入元素來實現我自己的項目中的這種效果。 – 2012-02-08 15:32:03