2015-09-06 137 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測試此功能。