1

我刚刚开始使用 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>&copy; @DateTime.Now.Year - My ASP.NET MVC Application</p>
                    </div>
                </div>
            </footer>

            @RenderSection("scripts", required: false)
        </body>
    </html>
4

1 回答 1

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>&copy; @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>
于 2013-02-14T17:43:41.980 回答