我有一個文本框在mvc4應用程序如下。如何刪除mvc4文本框中的默認日期?
@Html.TextBoxFor(x=>x.dateofAction, ViewBag.filterdateTime as string, new { @id = "dateofAction", @placeholder = "Date Of Action", @class = "txtBox form-control calender validate[required]" })
我對這個文本框使用jquery壓光機。
$(document).on('focus', '.calender', function(){
$(this).datepicker({
dateFormat: "dd/mm/yy",
changeMonth: true,
changeYear: true,
showOn: 'button',
buttonImage: '/images/icondate.png',
buttonImageOnly: true
})
});
這是我的模型
[DisplayName("dateofAction")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime dateofAction { get; set; }
我在第一次頁面加載默認的日期1/1/0001 12:00:00 AM
在文本框中顯示的是面臨的問題。其實我想顯示佔位符的價值。
我可以知道爲什麼我無法獲得佔位符值嗎?
讓你屬性可爲空 - 'public DateTime? dateofAction {get;組; }'(和**不**設置'value'屬性!) –
謝謝斯蒂芬。像'charm'這樣的作品 –
並且刪除'$(document).on('focus','.calender',function(){'並用'$('#dateofAction')替換它。datapicker({...} );'並移除'new {@id =「dateofAction」}(它已經有了'id') –