首次单击后,Bootstrap DropDown菜单不起作用

时间:2015-03-10 13:30:40

标签: html asp.net-mvc twitter-bootstrap drop-down-menu

我的_Layout.cshtml中有我的下拉菜单,点击其中一个菜单项第一次正常工作,例如带我到http://localhost:52098/Home/ViewTable/Scottish英超。

如果我再次点击该网址,它会尝试转到http://localhost:52098/Home/ViewTable/Home/ViewTable/Scottish英超

导航代码:

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>

看起来它已经从我已经开启的那个+路径上的href获取相对路径,那里我真正想要的是绝对路径?

1 个答案:

答案 0 :(得分:1)

添加&#39; /&#39;到您的网址开头

喜欢/Home/ViewMain/Scottish ChampionShip

使用

总是更好
@Url.Action("MethodName", "Controller")

e.g。

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

传递网址中的参数

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