Bootstrap DropDown menu not working after first click

I have my dropdown menu in my _Layout.cshtml and clicking on one of the menu items works fine the first time, for example http: // localhost: 52098 / Home / ViewTable / Scottish PM makes me .

If I hit the url again it tries to take me to http: // localhost: 52098 / Home / ViewTable / Home / ViewTable / Scottish Premier League

Navigation code:

div class="navbar navbar-inverse navbar-fixed-top">
            <ul class="nav nav-pills">
                <li role="presentation" class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
                        Scotland <span class="caret"></span></a>
                        <ul class="dropdown-menu multi-level" role="menu">
                            <li role="presentation"><a role="menuitem" tabindex="-1" href="Home/ViewTable/Scottish Premiership">
                                Scottish Premiership
                            </a></li>
                            <li role="presentation">
                                <a role="menuitem" tabindex="-1" href="Home/ViewMain/Scottish Championship">
                                    Scottish Championship
                                </a>
                            </li>
                            <li role="presentation">
                                <a role="menuitem" tabindex="-1">
                                   Scottish First Division
                                </a>
                            </li>
                            <li role="presentation">
                                <a role="menuitem" tabindex="-1">
                                   Scottish Second Division
                                </a>
                            </li>

                        </ul>
               </li>
                <li role="presentation" class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false">
                        England <span class="caret"></span>
                        <ul class="dropdown-menu" role="menu">
                            <li role="presentation">
                                <a role="menuitem" tabindex="-1" href="Home/ViewMain/Scottish Championship">
                                   English Premier League
                                </a>
                            </li>
                            <li role="presentation">
                                <a role="menuitem" tabindex="-1" href="Home/ViewMain/Scottish Championship">
                                   English Championship
                                </a>
                            </li>
                        </ul>
                </li>
            </ul>
           // @*@Html.MvcSiteMap().Menu(false, true, true, true, true)
            @Html.MvcSiteMap().SiteMapPath()*@


            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav"></ul>
            </div>

</div>

      

It looks like it takes a relative path from the one where I already included + href on the link, where do I really want the absolute path?

0


source to share


1 answer


Add '/' to the beginning of your urls

like /Home/ViewMain/Scottish ChampionShip

And it's always better to use

@Url.Action("MethodName", "Controller")

      



eg.

<a href="@Url.Action("MethodName", "Controller")"> Test</a>

      

Passing a parameter to a URL

  <a href="@Url.Action("MethodName", "Controller", new {LeagueName = "Scottish Premiership"})"> Test</a>

      

+1


source







All Articles