2012-03-14 52 views
0

我有一個日期選擇器控制在我的網站,當我點擊進入一個文本框,在日期選擇器中顯示:datepicker控件:爲什麼日期的年份顯示兩次?

enter image description here

但是當我點擊進入日起,我要顯示的問題日期:

enter image description here

年被顯示兩次......但我不知道爲什麼......我跟着這個tutorial

你能幫我找出爲什麼日期年份顯示兩次嗎?

Date.cshtml

@model DateTime 

<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> 

@Html.TextBox("", Model.ToString("dd/MM/yyyy"), 
       new { @class = "date" }) 

** TODO Wire up the date picker! ** 

EditorHookup.js

/// <reference path="~/Scripts/jquery-1.5.1.js" /> 
/// <reference path="~/Scripts/jquery-ui-1.8.11.js" /> 
$(document).ready(function() { 
$(".date").datepicker({ 
    //  buttonImage: "/content/images/calendar.gif", 
    //  showOn: "both", 
    //  defaultDate: $("#calendar-inline").attr('rel') 
    showAnim: 'slideDown', 
    dateFormat: 'dd/mm/yyyy' 

}); 
}); 

Create.cshtml(查看)

<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> 

Model類

public class Reservation 
{ 
    [Display(Name = "Date")] 
    [Column("Date")] 
    [DataType(DataType.Date)] 
    [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)] 
    public DateTime Date { get; set; } 
} 

最後控制器的創建方法

// GET: /Reservation/Create 

    public ActionResult Create() 
    { 
     return View(new Reservation { Date = DateTime.Now.Date}); 
    } 

回答

3

的問題可能是你的EditHookup.js在這條線:

dateFormat: 'dd/mm/yyyy' 

嘗試改變到:

dateFormat: 'dd/mm/yy' 
+1

+1自己蹲下這個洞。 – 2012-03-14 11:43:10

+0

你是對的!謝謝 ;) – Razor 2012-03-14 11:43:46

相關問題