我没有使用jquery.ui的datepicker,因为我需要在不同条件下选择整周和多个日期,所以我在EditorTemplate中使用Keith Wood的 datepicker作为我的Date字段:
@model Nullable<DateTime>
@{
string name = ViewData.TemplateInfo.HtmlFieldPrefix;
string id = name.Replace(".", "_");
string dt = Model.HasValue ? String.Format("{0:d}",(string)Model.Value.ToShortDateString()) : string.Empty;
}
@Html.TextBox("", dt, new { @class = "datefield", @type = "date", @id = id })
<script type="text/javascript">
$(document).ready(function () {
$('#@id').datepick({
renderer: $.datepick.themeRollerRenderer,
multiSelect: 999
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
使用文本框并使用日期选择器"弹出"时,验证工作正常; 但我真正想要的是使用内联日期选择器,但我无法在这些条件下进行验证:
@model Nullable<DateTime>
@{
string name = ViewData.TemplateInfo.HtmlFieldPrefix;
string id = name.Replace(".", "_");
string dt = Model.HasValue ? String.Format("{0:d}",(string)Model.Value.ToShortDateString()) : string.Empty;
}
<div class="kwdp">
</div>
@Html.Hidden("", dt, …Run Code Online (Sandbox Code Playgroud) asp.net-mvc jquery jquery-validate data-annotations unobtrusive-validation