Ren
Ren

Reputation: 1503

"Jquery Tabs" - navigation menu styling in Asp.net mvc?

I've just started using jQuery tabs, and it looks great. I would like to use them as my navigation menu in ASP.NET MVC. I cleaned up the site.css and have written the below code in my _Layout.cshtml. I can see the menu but it is not working correctly as i wanted. It loads the homepage every time no matter which link I select (it also displays the intended page, but below the contents of the home page).

  <!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>

Upvotes: 1

Views: 1489

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

You seem to have declared jquery twice (once at the beginning and once at the end) which obviously is wrong. Try fixing your scripts:

<!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>

Upvotes: 1

Related Questions