如何获取Html.Editorfor的日期选择器

在我的MVC3剃刀页面上,我有一个日期字段

@Html.EditorFor(model => model.Member.Dob) 

下面是我试图获得出生日期字段的日期选择器的代码。

       $(document).ready(function () { debugger; $("#Member_Dob").datepicker(); });  

但是当我运行这个页面时,我收到了错误

 Microsoft JScript runtime error: Object doesn't support property or method 'datepicker' 

请帮我找一种方法将datepicker添加到我的页面

您需要在Views \ Shared \ EditorTemplate文件夹中创建EditorTemplate。 将其命名为DateTime.cshtml。 应该看起来像下面这样:

 @model System.DateTime? 
@Html.Label("")
@Html.TextBox("", String.Format("{0:MM/dd/yyyy}",(Model == DateTime.MinValue)? null : Model), new { @class="text"})

使用方法如下:

 @Html.EditorFor(model => model.Member.Dob) 

本文完美地介绍了这一点: http : //blogs.msdn.com/b/stuartleeks/archive/2011/01/25/asp-net-mvc-3-integrating-with-the-jquery-ui-date-picker-和添加-A-jQuery的validation最新范围-validator.aspx