ASP.NET MVC EditorFor日期时间 [英] ASP.NET MVC EditorFor DateTime
本文介绍了ASP.NET MVC EditorFor日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何实现EditorFor日期时间?
How to implement EditorFor DateTime?
我已经有单独的日期和时间编辑器。我可以用它为我的DateTime编辑器?
I already have editors for Date and Time separately. Can I use it for my DateTime editor?
是否有任何建议,该怎么办呢?
Are there any suggestions, how to do it?
日期编辑:
@model DateTime
@Html.TextBox(string.Empty, (Model != default(DateTime) ? Model.ToShortDateString() : string.Empty), new { @class = "date form-control" })
时间编辑:
@model DateTime?
@Html.TextBox(string.Empty, (Model.HasValue ? Model.Value.ToString("HH:mm") : string.Empty), new { @class = "time form-control" })
我使用jQuery UI日期选择器日期编辑器。 Timepicker也是jQuery插件。
I am using jQuery UI datepicker for date editor. Timepicker is also jQuery plugin.
推荐答案
在查看/共享/ EditorTemplates创建DateTime.cshtml包含:
Create DateTime.cshtml in Views/Shared/EditorTemplates that contains:
@inherits System.Web.Mvc.WebViewPage<System.DateTime?>
@Html.TextBox("", string.Format("{0:yyyy-MM-dd HH:mm}",
Model.HasValue ? Model : null), new { @class = "dateTimePicker" })
和使用一些jQuery日期选择器。觉得这个作品具有默认jQuery UI的之一。
And use some jquery datepicker. think this one works with default jquery ui one.
这篇关于ASP.NET MVC EditorFor日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文