【问题标题】:Asp.net mvc 5 cross browser date picker and time pickerAsp.net mvc 5 跨浏览器日期选择器和时间选择器
【发布时间】:2015-09-06 22:57:30
【问题描述】:

我在 mvc5 中编程,但遇到了问题。

我的模特:

[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>

当我使用 Google chrome 日期选择器和时间选择器时显示正确,但是当我使用 mozilla firefox 时,这只是一个文本框。
我怎样才能概括它?我希望始终拥有日期选择器和时间选择器。

【问题讨论】:

标签: asp.net-mvc browser datepicker timepicker


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    • 2010-11-30
    • 2010-10-28
    相关资源
    最近更新 更多