2012-03-08 89 views
0

我下面这个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> 

那么,你知道为什么日期选取器不显示吗?在此先感谢

回答

3

您的部分视图模型未被调用,因为您的属性的DataType是错误的。更换

[DataType(DataType.DateTime)] 

[DataType(DataType.Date)] 

,并如预期正常工作了。

编辑

你也应该从局部视图中删除@inherits行继承不与模型不允许的。

+0

之后,我发现了一个HttpParseException:当使用'model'关键字时,不允许使用'inherits'关键字 – Razor 2012-03-08 12:31:45

+1

至少现在你知道你的部分视图你正在取得进展!你应该摆脱@inherits行。我正在更新我的答案。 – Falanwe 2012-03-08 12:35:58

+0

谢谢我删除@inherit行......但我现在有一个新的异常对不起:== > InvalidOperationException:传入字典的模型项目为空,但是这个字典需要一个类型为'System.DateTime'的非空模型项目。 – Razor 2012-03-08 12:41:37

0

我认为您的部分视图可能需要命名为DateTime.cshtml以匹配您的模型属性的类型。

2

我认为您的视图缺少对“〜/〜Scripts/jquery-1.5.1.js”脚本的引用。

+0

谢谢,我添加了引用,但是我的问题依然存在:( – Razor 2012-03-08 12:35:55

相关问题