我想在我的MVC4应用程序中使用JQueryUI,但我没有看到我想要的效果。 我会告诉你代码,我认为这是初学者的错误。我一定忘了指令。
_Layout.cshtml (只是声明)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8" />
<title>@ViewBag.Title - Mon application ASP.NET MVC</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@RenderSection("JavaScript", required: false)
@Styles.Render("~/Content/css")
myView.cshtml
@section JavaScript
{
<script type="text/javascript">
$(function () {
$("#dialog").dialog({
autoOpen: false,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
$("#opener").click(function () {
$("#dialog").dialog("open");
});
});
</script>
}
@{
ViewBag.Title = "Home Page";
}
@{
if (!Session.IsNewSession && Session.Contents["connecte"].Equals(true))
{
<div id="dialog" title="Basic dialog">
<p>This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
<button id="opener">Open Dialog</button>
}
else
{
<div class="group_bannner_right">
<img src="~/Images/picture.png" width="550" height="316" alt="baner">
</div>
<header class="group_bannner_left">
<hgroup>
<h1>Simple.Think. </h1>
<h2>
“The little things are infinitely the most important.“
</h2>
</hgroup>
</header>
}
}
我有这个错误:
Uncaught TypeError: Object [object Object] has no method 'dialog'
(index):18 (anonymous function)
(index):18 fire
jquery-1.8.2.js:988 self.fireWith
jquery-1.8.2.js:1096 jQuery.extend.ready
jquery-1.8.2.js:420 DOMContentLoaded
答案 0 :(得分:1)
未加载jQueryUI,按CTRL + SHIFT + F,搜索整个解决方案“〜/ bundles / jqueryui”。您将在BundleConfig.cs中看到一个查找匹配项,在那里您会发现jQuery位于您网站中的文件路径不正确。
如果您手动重新组织了jQuery UI文件,原因就在于此。
在BundleConfig.cs中编辑jQueryUI的文件路径,这样它是正确的,确保在更改BundleConfig.cs后构建项目。