0x800a1391 - JavaScript的运行时错误:'jQuery的'未定义 - MVC 4 [英] 0x800a1391 - JavaScript runtime error: 'jQuery' is undefined - MVC 4
问题描述
我想获得一个非常简单的模式对话框的运行。所以下面的教程我结束了这个code:
I want to get a really simple modal dialog running. So following a tutorial I end up with this code:
BundleConfig:
BundleConfig:
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-1.8.2.min.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui-1.8.24.js"));
_layout:
_Layout:
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - My ASP.NET MVC Application</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
</head>
<body>
<div id="body">
@RenderSection("featured", required: false)
<section class="content-wrapper main-content clear-fix">
@RenderBody()
</section>
</div>
<footer>
<div class="content-wrapper">
<div class="float-left">
<p>© @DateTime.Now.Year - My ASP.NET MVC Application</p>
</div>
</div>
</footer>
@RenderSection("scripts", required: false)
</body>
和指数:
@section featured {
<section class="featured">
<div class="content-wrapper">
<hgroup class="title">
<h1>@ViewBag.Title.</h1>
<h2>@ViewBag.Message</h2>
</hgroup>
<script type="text/javascript">
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
allFields.val( "" ).removeClass( "ui-state-error" );
}
});
$( "#create-user" )
.button()
.click(function() {
$( "#dialog-form" ).dialog( "open" );
});
</script>
<div style="float: left; width: 250px;">
<button id="create-user">Create new user</button>
</div>
</div>
</section>
}
然而,当我运行它,我结束了0x800a1391 - JavaScript的运行时错误:'jQuery的'是不确定的,jQuery的-UI库里面。如果我只是把code在它按预期的HTML页面。所以,问题来自于MVC项目。我使用的Visual Studio 2012在Windows 8有什么想法?
However when I run it I end up with 0x800a1391 - JavaScript runtime error: 'jQuery' is undefined, inside the jquery-ui library. If I simply put the code in an html page it works as expected. So the problem comes from the MVC project. I am using visual studio 2012 on Windows 8. Any thoughts?
推荐答案
默认情况下,MVC打捆忽略了文件名以 .min
文件。
By default, the MVC bundler ignores files with .min
in the filename.
使用jQuery的未缩小的版本来解决这个问题(或只是重命名文件) - 部署时,将打捆运行如下反正jQuery的文件。
Use the un-minified version of jQuery to fix the problem (or just rename the file) - when deployed, the bundler will minify the jQuery file anyway.
更新
您可以通过清除更改此行为的 IgnoreList
在 RegisterBundles
办法(但我建议使用默认设置粘并简单地重命名文件):
You can change this behavior by clearing the IgnoreList
in the RegisterBundles
method (but I recommend sticking with the defaults and simply renaming the files):
// Clear all items from the ignore list to allow minified CSS and JavaScript
// files in debug mode
bundles.IgnoreList.Clear();
// Add back the default ignore list rules sans the ones which affect minified
// files and debug mode
bundles.IgnoreList.Ignore("*.intellisense.js");
bundles.IgnoreList.Ignore("*-vsdoc.js");
bundles.IgnoreList.Ignore("*.debug.js", OptimizationMode.WhenEnabled);
查看更多在 Telerik的文档
这篇关于0x800a1391 - JavaScript的运行时错误:'jQuery的'未定义 - MVC 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!