我想显示一个datepicker我Html.EditorFor
要做到这一点,我在我的意见\共享\文件夹EditorTemplate,命名它创造了一个EditorTemplate DateTime.cshtml
但它不工作,而不是我收到错误--- Microsoft JScript runtime error: Object doesn't support property or method 'datepicker'
PLZ帮我解决这个错误
这是我的Razor视图页面
@model MyWebRole.ViewModels.ViewModelEvents
@{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset style="width:50%">
<legend>Event Details:</legend>
<div>
<table>
<tr>
<td>
@Html.EditorFor(model => model.vmStartDate)
@Html.ValidationMessageFor(model => model.vmStartDate)
</td>
</tr>
</table>
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
这里是我的DateTime.cshtml(粘贴下面)
@model System.DateTime?
<div class="editor-field">
@Html.TextBox("", String.Format("{0:MM/dd/yyyy}",(Model == DateTime.MinValue)? null : Model), new { @class="text"})
</div>
<script type="text/javascript">
$(document).ready(function () {
$("#@ViewData.ModelMetadata.PropertyName").datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'mm/dd/yy',
gotoCurrent: true
});
});
</script>
我能得到另一个视图日期选择器工作
@model MyWebRole.Models.Events
@{
ViewBag.Title = "Edit";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset style="width:50%">
<legend>Event Details:</legend>
<div>
<table>
<tr>
<td>
@Html.EditorFor(model => model.StartDate)
@Html.ValidationMessageFor(model => model.StartDate)
</td>
</tr>
</table>
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
两个剃刀视图之间的不同之处在于 - >第一个((日期选择器不工作)是使用一个ViewModel作为模型即(mywebrole.ViewModels.EventViewModel)
- >和第二个是使用myWebrole.models.Events(日期选择器工作正常)
这是一个问题?