默认的日期时间选择器在Visual Studio 2015年,仅显示日期选取器不允许选择时间 [英] Default datetime picker in visual studio 2015 showing only date picker not allowing to select time

查看:558
本文介绍了默认的日期时间选择器在Visual Studio 2015年,仅显示日期选取器不允许选择时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的视觉studiio 2015年,我用我的MVC5的应用程序的默认日期时间选择器。我面临的问题,同时显示日期时间选择器。它是只显示日期选择器而不是时间选择器。但我需要时间选择器也。这里是在模型的DateTimePicker我的code

I am using visual studiio 2015 and i am using its default datetime picker in my MVC5's App. i am facing problem while showing the datetime picker. it is showing only date picker and not time picker. but i need time picker also. here is my code of datetimepicker in model

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = false)]
[Required(ErrorMessage = "Start DateTime is required")]
public Nullable<System.DateTime> start_date_time { get; set; }

而我在日期的设置的DateTime 无控制器来,只有文本框出现。

while i set DateTime in place of Date No Controller comes only textbox appear.

推荐答案

有没有的默认的日期时间在MVC5 的选择器。什么 [数据类型] 属性的作用是使键入&LT属性;输入&GT; 元素的生成将随后被浏览器用来渲染适当控制HTML5如果支持。在 DataType.Date 的情况下,它会生成&LT;输入类型=日期... /&GT;

There is no default datetime picker in MVC5. What the [DataType] attribute does is render the type attribute for the <input> element your generating that will then be used by the browser to render the appropriate HTML5 control if supported. In the case of DataType.Date, it generates <input type="date" ... />

在当前时间只有最近的Chrome浏览器支持 TYPE =最新版本。如果该测试使用IE或Firefox,你只能得到一个标准的文本框。

At the current time only recent versions of Chrome support type="date". If you tested this using IE or FireFox, you would only get a standard textbox.

使用 [数据类型(DataType.DateTime)] 生成 TYPE =日期时间但目​​前暂不支持在这两种浏览器,IE或Firefox,这就是为什么你看到的只是标准的文本框。

Using [DataType(DataType.DateTime)] generates type="datetime" but this is not currently supported in either Chrome, IE or FireFox, which is why you see only the standard textbox.

Chrome浏览器最新版本但是做支撑 TYPE =日期时间本地这会使控制让您同时选择日期和时间。没有 [数据类型] 键入产生这一点,但你可以使用

Recent versions of Chrome however do support type="datetime-local" which will render a control allowing you to select both a date and a time. There is no [DataType] type which generates this but you can use

@Html.TextBoxFor(m => m.start_date_time, "{0:s}", new { @type = "datetime-local" })

请注意{0:秒} 速记{0:YYYY-MM-DDTHH:MM:SS}

您可以比较浏览器的各种版本,并且支持使用的HTML5的字段类型的这个网站

You can compare various versions of browsers and which of the HTML5 field types they support using this site.

由于目前的支持有限,我建议你考虑使用一个jQuery插件的DateTimePicker而不是浏览器的HTML实现。

Due to the current limited support, I recommend you consider using a jquery datetimepicker plugin rather than browsers HTML implementations.

这篇关于默认的日期时间选择器在Visual Studio 2015年,仅显示日期选取器不允许选择时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆