假设您为jQuery datepicker设置了编辑器:
@Html.EditorFor(model => model.DateOfBirth, new { @placeholder = "Date Of Birth", @class = "datefield", @type="text" })
通过浏览器调试检查您的JS代码是否正常工作,您的datepicker代码应如下所示:
$(document).ready(function () {
$(".datefield").datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
showOtherMonths: true,
selectOtherMonths: true,
// other datepicker settings here as you want
});
});
然后确保jQuery UI CSS文件包含在页面的 Layout.cshtml 内或head标签内,此步骤除日期编辑器外还应显示日历图像:
为了简化这些脚本和样式声明,我建议你学习MVC样式/脚本捆绑 .
欢迎任何建议 .