MVC 数据注释对应的日期时间选择器未在 Firefox 中显示
MVC Data Annotations corresponding DateTime picker not showing in Firefox
我有这样的模型
public class Movie
{
public int ID { get; set; }
[StringLength(60, MinimumLength = 3)]
public string Title { get; set; }
[Display(Name = "Release Date")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime ReleaseDate { get; set; }
....
}
和这个 属性 的日期时间应该在所有浏览器中呈现一个日期时间选择器,但它不会在 Firefox(版本 38.0.5)中发生,它在 Google [=21] 中工作=] , 有什么解决办法吗?
[Display(Name = "Release Date")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime ReleaseDate { get; set; }**
查看代码
@model MVCMovie.Models.Movie
....
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-group">
@Html.LabelFor(model => model.Title, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ReleaseDate, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ReleaseDate)
// @Html.TextBoxFor(model => model.ReleaseDate, new { @class = "form-control datepicker", placeholder = "Enter Drop-off date here..." })
@Html.ValidationMessageFor(model => model.ReleaseDate)
</div>
</div>
....
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
/* ... */
if (!Modernizr.inputtypes.date) {
$('.datepicker').datepicker();
}
</script>
}
我这样改了模型
public class Movie
{
public int ID { get; set; }
[StringLength(60, MinimumLength = 3)]
public string Title { get; set; }
[Required]
[Display(Name = "Release Date")]
//[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime ReleaseDate { get; set; }
.....
}
添加了 jQueryUI NuGet 包
创建了一个这样的包
//Create bundel for jQueryUI
//js
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jqueryui.js"));
//css
bundles.Add(new StyleBundle("~/Content/cssjqryUi").Include(
"~/Content/jqueryui.css"));
并在视图底部添加了这些部分
@section Scripts {
@Scripts.Render("~/bundles/jqueryui")
@Styles.Render("~/Content/cssjqryUi")
<script type="text/javascript">
$(document).ready(function () {
$('input[type=datetime]').datepicker({
dateFormat: "dd/M/yy",
changeMonth: true,
changeYear: true,
yearRange: "-60:+0"
});
});
</script>
}
它正在运行
我有这样的模型
public class Movie
{
public int ID { get; set; }
[StringLength(60, MinimumLength = 3)]
public string Title { get; set; }
[Display(Name = "Release Date")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime ReleaseDate { get; set; }
....
}
和这个 属性 的日期时间应该在所有浏览器中呈现一个日期时间选择器,但它不会在 Firefox(版本 38.0.5)中发生,它在 Google [=21] 中工作=] , 有什么解决办法吗?
[Display(Name = "Release Date")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime ReleaseDate { get; set; }**
查看代码
@model MVCMovie.Models.Movie
....
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-group">
@Html.LabelFor(model => model.Title, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ReleaseDate, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ReleaseDate)
// @Html.TextBoxFor(model => model.ReleaseDate, new { @class = "form-control datepicker", placeholder = "Enter Drop-off date here..." })
@Html.ValidationMessageFor(model => model.ReleaseDate)
</div>
</div>
....
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
/* ... */
if (!Modernizr.inputtypes.date) {
$('.datepicker').datepicker();
}
</script>
}
我这样改了模型
public class Movie
{
public int ID { get; set; }
[StringLength(60, MinimumLength = 3)]
public string Title { get; set; }
[Required]
[Display(Name = "Release Date")]
//[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime ReleaseDate { get; set; }
.....
}
添加了 jQueryUI NuGet 包
创建了一个这样的包
//Create bundel for jQueryUI
//js
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jqueryui.js"));
//css
bundles.Add(new StyleBundle("~/Content/cssjqryUi").Include(
"~/Content/jqueryui.css"));
并在视图底部添加了这些部分
@section Scripts {
@Scripts.Render("~/bundles/jqueryui")
@Styles.Render("~/Content/cssjqryUi")
<script type="text/javascript">
$(document).ready(function () {
$('input[type=datetime]').datepicker({
dateFormat: "dd/M/yy",
changeMonth: true,
changeYear: true,
yearRange: "-60:+0"
});
});
</script>
}
它正在运行