我想使用带有以下日期字段的 jQuery UI 日期选择器
<div class="editor-field">
@Html.EditorFor(model => model.CalibrationDate)
@Html.ValidationMessageFor(model => model.CalibrationDate)
</div>
我已经在我的视图中包含了所需的脚本和以下函数
<script src="@Url.Content("~/Scripts/jquery-1.7.1.js")" type="text/javascript"></script>
<script src="@Url.Content("~/jquery-ui-1.8.20.js")" type="text/javascript"></script>
<script>
$(document).ready(function () {
$('.date').datepicker({ dateFormat: "dd/mm/yy" }
});
看来我需要将日期类分配给我的
@Html.EditorFor(model => model.CalibrationDate)
你能建议我怎么做吗?或任何其他方法来获得此功能?
根据评论,这是最终的工作代码:
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$(".date").datepicker();
});
</script>
并且在体内
<div class="editor-label">
@Html.LabelFor(model => model.CalibrationDate)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.CalibrationDate, new{ Class = "datepicker" })
@Html.ValidationMessageFor(model => model.CalibrationDate)
</div>