【发布时间】:2011-08-22 08:21:27
【问题描述】:
在this blog 中应该解释如何为所有 DateTime 输入实现 jquery datepicker。但是,当我尝试遵循所采取的步骤时,我失败了。我怀疑我在某处设置了错误的引用,因为我的 VS 项目中现在已经有比博客中提到的更新(并且命名不同)的 .js 文件。有没有一个地方可以为绝对的 jquery NOOB 提供实现?
编辑: 我还找到了this link。在复制上述代码后,我在 jquery 1.5.1-min.js 中遇到一个异常,该异常表示该对象不支持该属性或方法...
编辑(2) 我对此一无所知,我尝试添加 Tridus 建议的参考,但我有不同的版本,并且在某些版本中我有一个 .min.js 替代方案。所有相关代码:
在 StandIn.cs 中:
[DisplayName("Available from")]
[DisplayFormat(DataFormatString="{0:d}",ApplyFormatInEditMode=true,NullDisplayText="(not specified")]
public DateTime? From { get; set; }
在 Edit.cshtml 中:
<div class="editor-field">
@Html.EditorFor(model => model.Standin.From)
@Html.ValidationMessageFor(model => model.Standin.From)
</div>
在_Layout.cshtml中:
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
</head>
在\Shared\EditorTemplates\DateTime.cshtml中
@model Nullable<System.DateTime>
@if (Model.HasValue)
{
@Html.TextBox("", Model.Value.ToShortDateString(), new { @class = "date" })
}
else
{
@Html.TextBox("",string.Empty)
}
<script type="text/javascript">
$(document).ready(function () { $('.date').datepicker({ dateFormat: "dd/mm/yy" }); });
</script>
注意:在我添加脚本标签之前,所有代码都可以正常执行:然后在显示 Edit.cshtml 时,jquery-1.5.1.min.js 会引发关于不支持的属性或方法的异常。
【问题讨论】:
标签: asp.net-mvc-3 jquery-ui jquery-ui-datepicker