在ASP.NET MVC 5.1 / HTML 5中显示DateTime选择器而不是Date选择器 [英] Displaying DateTime picker instead of Date picker in ASP .NET MVC 5.1/HTML 5 specific
本文介绍了在ASP.NET MVC 5.1 / HTML 5中显示DateTime选择器而不是Date选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字段:
[DisplayName(出生日期)]
[DataType(DataType.Date)]
public DateTime BirthDate {get;组;
然后在视图
< div class =form-group>
@ Html.LabelFor(model => model.BirthDate,htmlAttributes:new {@class =control-label col-md-2})
< div class =col-md- 10>
@ Html.EditorFor(model => model.BirthDate,new {htmlAttributes = new {@class =form-control}})
@ Html.ValidationMessageFor(model => model.BirthDate ,,新的{@class =text-danger})
< / div>
< / div>
其中转换为:
如果我只是更改属性上方的注释在模型中:
[DisplayName(出生日期)]
[DataType(DataType.DateTime)]
我没有显示任何选择器。如果我把它改成:
[DisplayName(出生日期)]
[DataType(DataType.Time )]
只有hh:mm可供选择。
问题:在ASP.NET MVC 5.1中显示DateTime选择器而不是Date选择器。我正在要求ASP .NET 5.1 HTML 5具体的解决方案。
解决方案
由于html5和浏览器支持,您正在获取此日期选择器html5。
可能的选项:
I write application in ASP .NET MVC 5.1
I have a field:
[DisplayName("Date of Birth")]
[DataType(DataType.Date)]
public DateTime BirthDate { get; set; }
and then in View
<div class="form-group">
@Html.LabelFor(model => model.BirthDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.BirthDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.BirthDate, "", new { @class = "text-danger" })
</div>
</div>
which translates to:
if I just change annotiations above property in model to:
[DisplayName("Date of Birth")]
[DataType(DataType.DateTime)]
I don't get any picker displayed. If I change them to:
[DisplayName("Date of Birth")]
[DataType(DataType.Time)]
there is only hh:mm to choose from.
Question: Displaying DateTime picker instead of Date picker in ASP .NET MVC 5.1. I am asking for ASP .NET 5.1 HTML 5 specific solution.
解决方案
You are getting this date picker because of html5 and browser supporting html5. Possible options :
这篇关于在ASP.NET MVC 5.1 / HTML 5中显示DateTime选择器而不是Date选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文