2014-04-04 134 views
0

我有MVC日期時間選擇器來獲取日期。當我添加日期時,它只會顯示日期。但是當我顯示隨時間顯示的日期時。我需要從這裏刪除時間。MVC日期時間選擇器

這是查看:

@Html.TextBoxFor(model => model.date, new { @class = "form-control input-sm", @data_provide = "datepicker" }) 

這是模態:

[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Resources.Resources))] 
     [Display(Name = "Maintenance Date")] 
     [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yy/MM/dd}")] 
     public virtual DateTime date { get; set; } 

回答

2

你可以試用一下下面的代碼?

@Html.TextBox(model => model.date, Model.date.ToString("MM/dd/yyyy"),new { @class = "form-control input-sm", @data_provide = "datepicker" }) 

OR

@Html.TextBoxFor(m => m.date, new { Value = Model.date.ToString("MM-dd-yyyy"), @class = "form-control input-sm", @data_provide = "datepicker" }) 
+0

其顯示的NAn /南壓光和文本框 – user2710638

+0

你可以嘗試我更新的答案@ user2710638 – Neel

0

添加 「{0:YY/MM/DD}」 到你的HTML幫助,所以現在看起來

@Html.TextBoxFor(model => model.date, "{0:yy/MM/dd}", new { @class = "form-control input-sm", @data_provide = "datepicker" })