MVC日期时间选择器

时间:2014-04-04 12:43:11

标签: asp.net-mvc razor

我有MVC日期时间选择器来获取日期。当我添加日期时,它将仅显示日期。但是,当我显示日期时,它会显示时间。我需要从中删除tiime。

这是视图:

@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 个答案:

答案 0 :(得分: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" }) 

答案 1 :(得分:0)

添加" {0:yy / MM / dd}"到您的HTML帮助器,现在看起来像

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