2015-09-06 141 views
0

我在mvc5编程,我有问题。Asp.net mvc 5跨浏览器日期选择器和时间选择器

我的模型:

[DataType(DataType.Date)] 
[Required(ErrorMessage = "Required")]   
public System.DateTime Date { get; set; } 

[DataType(DataType.Time)] 
[Required(ErrorMessage = "Required")] 
public System.DateTime Time { get; set; } 

查看:

<div class="form-group"> 
    @Html.LabelFor(model => model.Date, htmlAttributes:     new { @class = "control-label col-md-2" }) 
    <div class="col-md-10"> 
     @Html.EditorFor(model => model.Date, new { htmlAttributes = new { @class = "form-control" } }) 
     @Html.ValidationMessageFor(model => model.Date, "", new { @class = "text-danger" }) 
    </div> 
</div> 

<div class="form-group"> 
    @Html.LabelFor(model => model.Time, htmlAttributes: new { @class = "control-label col-md-2" }) 
    <div class="col-md-10"> 
     @Html.EditorFor(model => model.Time, new { htmlAttributes = new { @class = "form-control" } }) 
     @Html.ValidationMessageFor(model => model.Time, "", new { @class = "text-danger" }) 
    </div> 
</div> 

当我正确地使用谷歌chrome日期选取器和时间选择器显示,但是当我使用Mozilla Firefox浏览器,这只是一个文本框。
我怎么能概括它呢?我希望总是有日期选择器和时间选择器。

DataPicker and TimePicker in mozilla firefox and chrome

+1

FireFox不支持HTML5'input type =“date”'。请参阅[比较表](https://html5test.com/compare/browser/firefox-40/ie-11/chrome-44/safari-9.0.html) –

回答

0

的默认编辑模板使用HTML输入型 '日期',这可能是not supported in firefox。如果浏览器不支持日期输入类型,我们创建了一个自定义editor template,它返回到jQuery日期选择器(选择任何js日期选择器,有很多)。

如果需要,您可以使用modernizr测试此功能。