简体   繁体   English

带有Bootstrap的C#ASP.NET

[英]C# ASP.NET with Bootstrap

I'm trying to generate anchors using @Html.ActionLink in a Bootstrap style Nav bar. 我正在尝试在Bootstrap样式导航栏中使用@ Html.ActionLink生成锚点。 I'm having trouble making the tabs switch active, what's the best way to accomplish this? 我在使选项卡开关处于活动状态时遇到麻烦,实现此目的的最佳方法是什么?

I've tried to append data-toggle="pill" to the a tags after the are generated but that doesn't seem to work. 我试图在data生成后将data-toggle =“ pill”附加到a标签,但这似乎不起作用。

Code: 码:

            <ul class="nav nav-pills nav-justified" id="myTab">
                <li class="active">@Html.ActionLink("Home", "Index", "Home")</li>
                <li>@Html.ActionLink("Movies", "Index", "Movies")</li>
                <li>@Html.ActionLink("About", "About", "Home")</li>
                <li>@Html.ActionLink("Bootstrap Test", "Bootstrap", "Home")</li>
            </ul>

Thanks. 谢谢。

I don't see anything wrong with your code, though this might not be the exact problem you are facing, following blog post might help you to switch a tab dynamically. 我看不到您的代码有什么问题,尽管这可能并不是您要面对的确切问题,但在博客文章之后可能会帮助您动态切换标签。

https://madushaonline.wordpress.com/2013/09/24/active-links-on-bootstrap-navbar-with-asp-net-mvc/ https://madushaonline.wordpress.com/2013/09/24/active-links-on-bootstrap-navbar-with-asp-net-mvc/

Use a overloaded ActionLink method which is accepting html parameters and pass the @class=active and you need to replace data- to data_ (underscore) in MVC. 使用接受HTML参数并传递@class=activeoverloaded ActionLink method ,您需要在MVC中将data-替换为data_ (下划线)。

 <ul class="nav nav-pills">
  <li>
    @Html.ActionLink("Home", "Index", "Home", null, new {@class = "active",  
                     @data_toggle="pill" })
  </li>
  <li>@Html.ActionLink("Movies", "Index", "Movies")</li>
  <li>@Html.ActionLink("About", "About", "Home")</li>
  <li>@Html.ActionLink("Bootstrap Test", "Bootstrap", "Home")</li>
 </ul>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM