我下面这个tutorial来显示日期选择器,当我点击进入一个文本框......但日期选取器不显示...为什么datepicker不显示在我的MVC 3网站?
模型类(预约):
[Required(ErrorMessage = "Date requise.")]
[Display(Name = "Date")]
[Column("Date")]
[DataType(DataType.DateTime)]
public DateTime Date { get; set; }
EditorHookup.js
/// <reference path="~/Scripts/jquery-1.5.1.js" />
/// <reference path="~/Scripts/jquery-ui-1.8.11.js" />
$(document).ready(function() {
$('.date').datepicker({ dateFormat: "dd/mm/yy" });
});
局部视图(Date.cshtml)
@inherits System.Web.Mvc.WebViewPage<System.DateTime?>
@model DateTime
@Html.TextBox("", Model.ToString("dd/MM/yyyy"),
new{@class="date"})
** TODO Wire up the date picker! **
我的观点
@model TennisOnline.Models.Reservation
@{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Create</h2>
<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-ui-1.8.11.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/EditorHookup.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Reservation</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Date)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Date)
@Html.ValidationMessageFor(model => model.Date)
</div>
那么,你知道为什么日期选取器不显示吗?在此先感谢
之后,我发现了一个HttpParseException:当使用'model'关键字时,不允许使用'inherits'关键字 – Razor 2012-03-08 12:31:45
至少现在你知道你的部分视图你正在取得进展!你应该摆脱@inherits行。我正在更新我的答案。 – Falanwe 2012-03-08 12:35:58
谢谢我删除@inherit行......但我现在有一个新的异常对不起:== > InvalidOperationException:传入字典的模型项目为空,但是这个字典需要一个类型为'System.DateTime'的非空模型项目。 – Razor 2012-03-08 12:41:37