简体   繁体   English

MVC4和datepicker:“0x800a01b6 - JavaScript运行时错误:对象不支持属性或方法'datepicker'”

[英]MVC4 and datepicker: “0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'datepicker'”

I have an MVC application that gives the above error. 我有一个MVC应用程序,给出了上述错误。 the application defaulted to referencing jquery-1.8.2.js in the Scripts folder. 应用程序默认引用Scripts文件夹中的jquery-1.8.2.js。 With NuGet, I added jquery-ui-1.11.4.js. 在NuGet中,我添加了jquery-ui-1.11.4.js。

Here are the relevant code sections: 以下是相关的代码部分:

BundleConfig.cs: BundleConfig.cs:

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

        bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
                    "~/Scripts/jquery-ui-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.unobtrusive*",
                    "~/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 StyleBundle("~/Content/css").Include("~/Content/site.css"));

        bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
                    "~/Content/themes/base/jquery.ui.core.css",
                    "~/Content/themes/base/jquery.ui.resizable.css",
                    "~/Content/themes/base/jquery.ui.selectable.css",
                    "~/Content/themes/base/jquery.ui.accordion.css",
                    "~/Content/themes/base/jquery.ui.autocomplete.css",
                    "~/Content/themes/base/jquery.ui.button.css",
                    "~/Content/themes/base/jquery.ui.dialog.css",
                    "~/Content/themes/base/jquery.ui.slider.css",
                    "~/Content/themes/base/jquery.ui.tabs.css",
                    "~/Content/themes/base/jquery.ui.datepicker.css",
                    "~/Content/themes/base/jquery.ui.progressbar.css",
                    "~/Content/themes/base/jquery.ui.theme.css"));
    }
}

} }

_Layout.cshmtl: _Layout.cshmtl:

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/themes/base/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
<script src="@Url.Content("~/Scripts/FloatingDiv.js")"></script>

And the view where the datepicker lives: 以及datepicker所在的视图:

@using (Html.BeginForm())
{
<div class="container">
    <div class="left-third">
        <label for="Company">Company:</label>
        @Html.DropDownList("Company")
    </div>
    <div class="middle-third" style="padding-left:20px">
        <label for="StartDate">Start Date:</label>
        @Html.TextBox("StartDate", null, new { @class = "datefield input-box" })
    </div>
    <div class="right-third" style="padding-left:20px">
        <label for="EndDate">End Date:</label>
        @Html.TextBox("EndDate", null, new { @class = "datefield input-box" })
    </div>
</div>
<br />
<br />
<br />

<div style="width:100%;text-align:center">
     <input class="button" type="submit" value="Generate Report" />
</div>
}
<script type="text/javascript">
$(function () {
    $('.datefield').datepicker();
});

I have tried referencing the scripts with a script tag and using the @Url.Content function for all the various scripts, for example: 我尝试使用脚本标记引用脚本,并使用@ Url.Content函数处理所有各种脚本,例如:

<script src="@Url.Content("~/Scripts/jquery-ui-1.11.4.js")"></script>

I have tried the "Networking" tab of the developer tools (F12) in IE to ensure that the scripts were loaded, and they are with a result of 200. I did notice that the 我已经尝试了IE中的开发人员工具(F12)的“网络”选项卡,以确保脚本已加载,并且结果为200.我确实注意到

@Styles.Render("~/Content/themes/base/css")

didn't render in the networking tab. 没有在网络选项卡中呈现。 I don't know if that is relevant, but I think it just comes with the 我不知道这是否相关,但我认为它只是随之而来的

@Styles.Render("~/Content/css")

I tried moving the script references around and the datepicker method around to no avail. 我尝试移动脚本引用和周围的datepicker方法无济于事。

I sincerely hope one of you smart guys or gals will know what to do about this. 我真诚地希望你们中的一个聪明人或者gals会知道怎么做。

As nearly all of you surmised, I was doing something wrong. 几乎所有人都猜测,我做错了什么。

I made a new project and used the @Scripts.Render to add the appropriate jquery-1.8.2.js and jquery-ui.1.8.24.js that are included with the MVC4 project and they worked fine. 我创建了一个新项目,并使用@ Scripts.Render添加了MVC4项目中包含的相应的jquery-1.8.2.js和jquery-ui.1.8.24.js,它们运行良好。 I did have to move the Render to the top underneath @Scripts.Render("~/bundles/modernizr"). 我确实必须将Render移到@ Scripts.Render(“〜/ bundles / modernizr”)下面的顶部。

I then went back to the original project, uninstalled jquery-ui-1.11.4.js with the NuGet Package Manager that I had mistakenly installed earlier, and manually copied the jquery-ui-1.8.24.js files and CSS sheets from the new test project to the old solution. 然后我回到原来的项目,用我之前错误安装的NuGet包管理器卸载了jquery-ui-1.11.4.js,并手动复制了jquery-ui-1.8.24.js文件和CSS表。新解决方案的新测试项目。 Then, knowing that multiple copies of the script would bollix things up, I searched in the master page for 'jquery.' 然后,知道脚本的多个副本可以解决问题,我在母版页中搜索了“jquery”。 To nobody's surprise, there was the reference to the original file just above the </body> tag. 令人惊讶的是,在</body>标签正上方有对原始文件的引用。 I removed it, made sure all the bundles were referencing the correct files, that the files were there and there were no duplicates again, and everything works fine. 我删除它,确保所有捆绑包引用正确的文件,文件在那里,并没有重复,一切正常。

Thanks for putting up with my idiocy. 谢谢你忍住我的愚蠢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 0x800a01b6-JavaScript运行时错误:对象不支持属性或方法“ appendTo” - 0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'appendTo' 0x800a01b6-JavaScript运行时错误:对象不支持属性或方法“ cookie” - 0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'cookie' 0x800a01b6 - JavaScript运行时错误:对象不支持属性或方法'tabs' - 0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'tabs' 0x800a01b6-JavaScript运行时错误:对象不支持属性或方法“时间选择器” - 0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'timepicker' 0x800a01b6-JavaScript运行时错误:对象不支持属性或方法&#39;SumoSelect&#39; - 0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'SumoSelect' 0x800a01b6-JavaScript运行时错误:对象不支持属性或方法“ getElementsByTagName” - 0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'getElementsByTagName' 0x800a01b6-JavaScript运行时错误:对象不支持属性或方法“调用” - 0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'call' ul上的JQuery菜单方法抛出“ 0x800a01b6-Microsoft JScript运行时错误:对象不支持此属性或方法” - JQuery menu method on ul throws “0x800a01b6 - Microsoft JScript runtime error: Object doesn't support this property or method” 错误 0x800a01b6 - 对象不支持属性或方法“attachEvent” - Error 0x800a01b6 - Object doesn't support property or method 'attachEvent' IE9中的Jquery 2.1.1得到错误:0x800a01b6-Microsoft JScript运行时错误:对象不支持属性或方法&#39;addEventListener&#39; - Jquery 2.1.1 in IE9 get error: 0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'addEventListener'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM