2014-01-10 46 views
3

我已經在製作一個MVC5站點了,如你所知。現在我剛剛創建了一個使用具有生日日期字段的克里特模板的視圖。 Andit沒有在IE中顯示,並且在文本框中顯示大量gliph的Chrome中顯示如下,因爲您可以在下圖中比較。IE不渲染MVC5的DatePicker

enter image description here

這是怎麼回事,我如何才能讓IE瀏覽器顯示的日期選擇器一樣簡單的Chrome做,以及如何clena它一點。我認爲這些槓桿是無用的和混亂的。

這裏是我在我的模型

[Display(Name = "Fecha de nacimiento")] 
    [DataType(DataType.Date)] 
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")] 
    public DateTime BirthDate { get; set; } 

,並在視圖定義的屬性

<div class="form-group"> 
     @Html.LabelFor(model => model.BirthDate, new { @class = "control-label col-md-2" }) 
     <div class="col-md-10"> 
      @Html.EditorFor(model => model.BirthDate) 

      @Html.ValidationMessageFor(model => model.BirthDate) 
     </div> 
    </div> 

回答

3

如果你不喜歡內置的日期選擇器(這是由瀏覽器呈現因爲它是輸入類型=「日期」),那麼有很多第三方插件可用,如jQuery UI

您需要潛在更改的一件事是,您可能需要使用EditorFor而不是使用TextBoxFor,因此瀏覽器會將其視爲普通文本框。下面是使用jQuery UI的例子:

@Html.TextBoxFor(m => m.BirthDate) 

<script> 
    $(function() { 
     $('#BirthDate').datepicker(); 
    }); 
+0

但是爲什麼IE沒有顯示任何日期選取器,這是我想要的問題之一。 Imakeit如何工作。這是在Win8上運行的IE10。 –

+0

我不確定IE10是否全面支持HTML 5.請檢查http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_input_type_date – Dismissile

+0

不,他們不會:他們整天都在做什麼?我正在和jquery進行交流,讓你知道並標記爲答案。 –

2

感謝@Dissmissile我弄明白自舉日期選擇器,但有點

@Html.TextBoxFor(model => model.Date, new { @class = "datepicker" }) 

然後我添加的下一個js代碼配置的格式在我看來,不同的和行爲

$(document).ready(function() { 
     $(".datepicker").datepicker({ 
      format: "yyyy/mm/dd", 
      autoclose: true 
     }); 
     $(".datepicker").datepicker('setValue', new Date()); 
    });