带有MVC3问题的Superfish菜单(对象预期错误) [英] Superfish menu with MVC3 Issue (Object Expected error)
问题描述
我有一个站点,它是一个ASP.Net MVC3 Web应用程序.由于需要子菜单,因此决定使用SuperFish插件.
我下载了代码,然后使用ul class ="sf-menu"将子菜单添加到菜单中.
当我进入主页(哪个是Index.cshtml)时,一切正常(可能是因为这是我的主页,并且JavaScript已加载一次).当我尝试加载其他页面时,我在JQuery函数上收到错误(期望的对象).
如果删除此功能,则不会出现错误,但好像没有加载SuperFish CSS文件,并且菜单显示为TreeView.
我试图用谷歌搜索这个问题,并找到了一些答案,其中将JQuery函数放在PlaceHolder之后应该可以解决问题.我尝试了,但没有.现在,在加载主页时,也会出现预期对象"错误.
现在的代码:
Hi,
I have a site which is an ASP.Net MVC3 Web Application. Since I needed sub-menus, I decided to use the SuperFish plugin.
I downloaded the code, and added to my menu the sub-menues using, of course, the ul class="sf-menu".
When I get to me home page (Which is the Index.cshtml), everything is ok (probably since it''s my home page and the JavaScripts was loaded once). When I try to load a different page I get an error (Object Expected) on the JQuery function.
If I delete this function, I don''t get an error but it''s as if the SuperFish CSS file is not loaded and the menu appears as a TreeView.
I tried to google the issue and found some answers in which putting the JQuery function after a PlaceHolder should resolve the problem. I tried and it didn''t. Now I get the Object Expected error also when loading my home page.
The code as it is now:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
@*<title>@ViewBag.Title</title>*@
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="css/superfish.css" media="screen">
<script type="text/javascript" src="<%=Url.Content("~/js/jquery-1.2.6.min.js")%>"></script>
@*<%=ResolveClientUrl("~/js/superfish.js")%>*@
<asp:ContentPlaceHolder ID="head" runat="server"/>
<script type="text/javascript" src="<%=Url.Content("~/js/hoverIntent.js")%>"></script>
<script type="text/javascript" src="<%=Url.Content("~/js/superfish.js")%>"></script>
<script type="text/javascript">
jQuery(function () {
jQuery('ul.sf-menu').superfish();
});
</script>
</head>
<body>
<div class="page">
<header>
<div id="title">
<h1>My MVC Application</h1>
</div>
<div id="logindisplay">
@Html.Partial("_LogOnPartial")
</div>
<nav>
<ul class="sf-menu">
<li class="current">
<a href="#a">1st menu item</a>
<ul>
<li>
<a href="#aa">menu item 1</a>
</li>
<li class="current">
<a href="#ab">menu item 2</a>
<ul>
<li class="current">
<a href="#">menu item 21</a>
</li>
</ul>
</li>
</ul>
</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Home", "Index", "Home")</li>
</ul>
</nav>
</header>
<section id="main">
@RenderBody()
</section>
<footer>
</footer>
</div>
</body>
</html>
注释:
1."js"是解决方案一部分的文件夹,它直接在解决方案的文件夹下. css文件夹是相同的.
2.在修复PlaceHolder之前,我也没有使用"Url.Content".添加后,加载主页时也会出现该错误.
代码:
Notes:
1. "js" is a folder which is part of the solution, it is directly under the solution''s folder. The css folder is the same.
2. Before the PlaceHolder fix, I also didn''t use the "Url.Content". After adding that The error appeared also when loading the home page.
The Code:
<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="js/hoverIntent.js"></script>
<script type="text/javascript" src="js/superfish.js"></script>
<script type="text/javascript">
jQuery(function () {
jQuery('ul.sf-menu').superfish();
});
</script>
推荐答案
尝试一下.效果很好.
所有 SuperFish 文件都在/superfish/
中
Try this. It works fine.
all SuperFish files are in/superfish/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="/superfish/css/superfish.css" media="screen" />
<script type="text/javascript" src="/superfish/js/hoverIntent.js"></script>
<script type="text/javascript" src="/superfish/js/superfish.js"></script>
<script type="text/javascript">
// initialise plugins
jQuery(function () {
jQuery('ul.sf-menu').superfish();
});
</script>
</head>
<body>
<div class="page">
<header>
<div id="title">
<h1>
My MVC Application</h1>
</div>
<div id="logindisplay">
@Html.Partial("_LogOnPartial")
</div>
<nav>
<ul class="sf-menu">
<li class="current"><a href="#a">menu item</a>
<ul>
<li><a href="#aa">menu item that is quite long</a> </li>
<li class="current"><a href="#ab">menu item</a>
<ul>
<li class="current"><a href="#">menu item</a></li>
<li><a href="#aba">menu item</a></li>
</ul>
</li>
<li><a href="#">menu item</a>
<ul>
<li><a href="#">menu item</a></li>
<li><a href="#">menu item</a></li>
<li><a href="#">menu item</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#">menu item</a> </li>
<li><a href="#">menu item</a>
<ul>
<li><a href="#">menu item</a>
<ul>
<li><a href="#">short</a></li>
<li><a href="#">short</a></li>
</ul>
</li>
<li><a href="#">menu item</a>
<ul>
<li><a href="#">menu item</a></li>
<li><a href="#">menu item</a></li>
<li><a href="#">menu item</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#">menu item</a> </li>
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
</ul>
</nav>
</header>
<section id="main">
@RenderBody()
</section>
<footer>
</footer>
</div>
</body>
</html>
Thanks
I actually did move the files, but not to this directory but to the directory in which there were already Javascripts (Scripts folder).
I also moved the css file to the Content folder and it worked ! :)
By the way, both folders are default directory, that when you create a new MVC3 Web Application they are created.
Thanks
I actually did move the files, but not to this directory but to the directory in which there were already Javascripts (Scripts folder).
I also moved the css file to the Content folder and it worked ! :)
By the way, both folders are default directory, that when you create a new MVC3 Web Application they are created.
这篇关于带有MVC3问题的Superfish菜单(对象预期错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!