【问题标题】:Bootstrap DropDown menu doesn't work after first click首次单击后引导下拉菜单不起作用
【发布时间】:2015-05-11 23:19:27
【问题描述】:

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

如果我再次点击该 URL,它会尝试将我带到 http://localhost:52098/Home/ViewTable/Home/ViewTable/Scottish Premiership

导航代码:

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中获取相对路径,而我真正想要的是绝对路径?

【问题讨论】:

  • 在您的网址开头添加“/”

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


【解决方案1】:

在 URL 的开头添加“/”

点赞/Home/ViewMain/Scottish ChampionShip

而且总是更好用

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

例如

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

在 URL 中传递参数

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

【讨论】:

  • 啊,是的,这有点像新手错误。我没有使用 htmlhelper 等做大量工作,我确实考虑过使用 ActionLinks 等,但不是 100% 确定如何在 href 标记中执行此操作,所以谢谢你:)
  • 虽然我一直在使用 link_to,但我遇到了类似的问题:
猜你喜欢
相关资源
最近更新 更多
热门标签