2015-02-09 79 views
0

我正在構建一個MVC 5應用程序,我正在嘗試使用Bootstrap.v3.Datetimepicker.CSSMVC 5 Bootstrap.v3.Datetimepicker.CSS錯誤:對象不支持屬性或方法'datetimepicker'

我有

$(document).ready(
function() { 
    $('.datetimepicker').datetimepicker({ 
     changeMonth: true, 
     changeYear: true, 
     dateFormat: "dd/mm/yyyy" 
    }); 
}); 

這是我的包怎麼看起來像

public static void RegisterBundles(BundleCollection bundles) 
    { 
     bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
        "~/Scripts/jquery-{version}.js")); 

     bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
        "~/Scripts/jquery.validate*")); 

     // Use the development version of Modernizr to develop with and learn from. Then, when you're 
     // ready for production, use the build tool at http://modernizr.com to pick only the tests you need. 
     bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
        "~/Scripts/modernizr-*")); 

     bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
        "~/Scripts/bootstrap.js", 
        "~/Scripts/bootstrap-datepicker.js", 
        "~/Scripts/DatePickerReady.js", 
        "~/Scripts/respond.js")); 

     bundles.Add(new ScriptBundle("~/bundles/moment").Include(
        "~/Scripts/moment.js")); 

     bundles.Add(new StyleBundle("~/Content/css").Include(
        "~/Content/bootstrap.css", 
        "~/Content/bootstrap-datetimepicker.min.css", 
        "~/Content/site.css")); 

     // Set EnableOptimizations to false for debugging. For more information, 
     // visit http://go.microsoft.com/fwlink/?LinkId=301862 
     BundleTable.EnableOptimizations = true; 

這是視圖

<h2>Create</h2> 

@using (Html.BeginForm()) 
{ 
    @Html.AntiForgeryToken() 

    <div class="form-horizontal"> 
     <h4>CreateEditSeasonViewModel</h4> 
     <hr /> 
     @Html.ValidationSummary(true, "", new { @class = "text-danger" })     

     <div class="form-group"> 
      @Html.LabelFor(model => model.StartDate, htmlAttributes: new { @class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.EditorFor(model => model.StartDate, new { htmlAttributes = new { @class = "form-control datetimepicker", placeholder = "Enter start date here..." } }) 
       @Html.ValidationMessageFor(model => model.StartDate, "", new { @class = "text-danger" }) 
      </div> 
     </div> 

     <div class="form-group"> 
      @Html.LabelFor(model => model.EndDate, htmlAttributes: new { @class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.EditorFor(model => model.EndDate, new { htmlAttributes = new { @class = "form-control datetimepicker", placeholder = "Enter end date here..." } }) 
       @Html.ValidationMessageFor(model => model.EndDate, "", new { @class = "text-danger" }) 
      </div> 
     </div> 

     <div class="form-group"> 
      <div class="col-md-offset-2 col-md-10"> 
       <input type="submit" value="Create" class="btn btn-default" /> 
      </div> 
     </div> 
    </div> 
} 

    <div> 
     @Html.ActionLink("Back to List", "Index") 
    </div> 

當我運行該應用程序我得到一個JavaScript文件這個錯誤在IE 11和Firefox中。 IE 11 runtime error

我在做什麼錯,我該如何擺脫這個障礙?

更新:我跟隨了一些博客,包括這些;

adding-datetimepicker-control-to-mvc-project

bootstrap-datetimepicker

+0

您的datetimepicker文件名爲'bootstrap-datetimepicker.js'嗎?檢查你的腳本文件夾,然後檢查你的捆綁包。 – Jasen 2015-02-10 00:00:40

+0

@Jasen datetimepicker是該組中js函數的一部分(bootstrap包)。我將文件命名爲DatePickerReady – Komengem 2015-02-10 00:03:41

+0

因此,您將'bootstrap-datetimepicker.js'重命名爲'DatePickerReady.js'?加載頁面資源時你有404s嗎? – Jasen 2015-02-10 00:08:54

回答

0

這聽起來像你的插件中,無法加載,或者在時間上沒有得到加載。有些事情要檢查:

  • 你重建了你的項目?
  • 您是否使用過螢火蟲或其他開發人員工具以確保datepicker JavaScript正在加載?
  • 你是否按照正確的順序放置引導程序和jquery包?
  • 在你打電話給datetimepicker()之前,你正在加載它們嗎?
+0

jQuery在引導之前運行,然後運行我的自定義文件。我甚至試圖將這些軟件包放在佈局頁面的頂部,正如底部的默認設置一樣。沒有什麼工作仍在繼續,我收到了同樣的錯誤。我知道'DatePickerReady.js'正在運行,因爲方法'datetimepicker'顯示在錯誤 – Komengem 2015-02-10 02:51:21

+0

@Komengem事實上,datetimepicker顯示在你的錯誤消息中只能證明你正在調用datetimepicker(),它並不表示它正確加載 - 實際上它可能恰恰相反。 – joelmdev 2015-02-10 03:38:09

相關問題