本文介绍了MVC DateTime文本框格式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做

model.PickupDate.ToString("d")

但是MVC4不太喜欢. PickupDate是一个DateTime字段,我想剥离显示在视图中的时间部分,同时保留将TextBoxFor绑定到javasript datepicker的new { id = "date1" }代码.如何仅在这种情况下显示日期部分?

But MVC4 is not liking that very much. PickupDate is a DateTime field and I would like to strip off the time portion when displayed in the view, while keeping the new { id = "date1" } code which binds the TextBoxFor to the javasript datepicker. How can I display the Date portion only in this instance?

@Html.TextBoxFor(model => model.PickupDate, new { id = "date1" })

推荐答案

这就是我要这样做的方式.希望对您有帮助

this is how I would do this. Hope it helps

 @Html.TextBoxFor(m => m.MyDateTime, new { Value = Model.MyDateTime.ToString("MM-dd-yyyy"), id = "MySuperCoolId"});

或者您的情况

@Html.TextBoxFor(m => m.PickupDated, new { Value = Model.PickupDate.ToString("d"), id = "date1"});

这篇关于MVC DateTime文本框格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 05:37