我刚开始使用jQuery标签,看起来很棒。我想将它们用作ASP.NET MVC
中的导航菜单。我清理了site.css
,并在我的_Layout.cshtml
中编写了以下代码。我可以看到菜单,但它根本无法正常工作。无论我选择哪个链接(它还显示目标页面,但在主页内容下面),它每次都会加载主页。
<!DOCTYPE html>
<html lang="en">
<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/themes/base/css")
@Styles.Render("~/Content/bootstrap")
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/bootstrap")
<script>
$(function () {
$("#tabs").tabs({ active: false });
});
</script>
</head>
<body>
<header>
<div >
<div >
<p >@Html.ActionLink("your logo here", "Index", "Home")</p>
</div>
<div >
<section>
Hello, <span >@User.Identity.Name</span>!
</section>
<nav>
<div id = "tabs">
<ul >
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</div>
</nav>
</div>
</div>
</header>
<div >
@RenderSection("featured", required: false)
<section class="content-wrapper main-content clear-fix">
@RenderBody()
</section>
</div>
<footer>
<div >
<div >
<p>© @DateTime.Now.Year - My ASP.NET MVC Application</p>
</div>
</div>
</footer>
@RenderSection("scripts", required: false)
</body>
</html>
答案 0 :(得分:1)
你似乎已经两次声明jquery(一次在开头,一次在结尾),这显然是错误的。尝试修复脚本:
<!DOCTYPE html>
<html lang="en">
<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/themes/base/css")
@Styles.Render("~/Content/bootstrap")
@Styles.Render("~/Content/css")
</head>
<body>
<header>
<div>
<div>
<p>@Html.ActionLink("your logo here", "Index", "Home")</p>
</div>
<div>
<section>
Hello, <span >@User.Identity.Name</span>!
</section>
<nav>
<div id="tabs">
<ul>
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</div>
</nav>
</div>
</div>
</header>
<div>
@RenderSection("featured", required: false)
<section class="content-wrapper main-content clear-fix">
@RenderBody()
</section>
</div>
<footer>
<div>
<div>
<p>© @DateTime.Now.Year - My ASP.NET MVC Application</p>
</div>
</div>
</footer>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
@Scripts.Render("~/bundles/modernizr")
<script>
$("#tabs").tabs({ active: false });
</script>
</body>
</html>