简体   繁体   English

如何在MVC Razor中使用Bootstrap Badge类?

[英]How can I use the Bootstrap Badge class within MVC Razor?

How can I use the Bootstrap Badge class to show a number next to the button? 如何使用Bootstrap Badge类在按钮旁边显示数字? In this case I am using the @ActionLink. 在这种情况下,我使用@ActionLink。 I've seen on the bootstrap page that I'm supposed to use a HTML span for the Badge. 我在引导页面上看到应该为徽标使用HTML跨度。

Code: 码:

        <div class="row">
            <div class="col-md-2">
                <div class="list-group">
                    @Html.ActionLink("Home", "Index", "Home", null, new { @class = "list-group-item" })
                    @Html.ActionLink("Auto's", "Lijst", "Auto", null, new { @class = "list-group-item" })
                    @Html.ActionLink("Medewerkers", "Lijst", "Medewerker", null, new { @class = "list-group-item" })
 <!--This one!-->   @Html.ActionLink("Dagprogramma", "Dagprogramma", "Medewerker", null, new { @class = "list-group-item"} )
                    @Html.ActionLink("Contact", "Contact", "Home", null, new { @class = "list-group-item" })
                </div>
            </div>

You cannot include custom html markup inside the link markup generated by ActionLink helper method. 您不能在ActionLink帮助程序方法生成的链接标记中包含自定义html标记。 What you can do is, write an anchor tag and include the span inside that. 您可以做的是编写一个锚标记,并在其中包含跨度。 Use the Url.Action method to generate the correct relative url to the action method which you will use as the link's href attribute value. 使用Url.Action方法生成与该操作方法相对应的正确url,您将用作链接的href属性值。

 @Html.ActionLink("Medewerkers", "Lijst", "Medewerker", null, 
                                                   new { @class = "list-group-item" })

  <a href="@Url.Action("Dagprogramma","Medewerker")"
                class="list-group-item"> Dagprogramma <span class="badge">99</span>
  </a>
  @Html.ActionLink("Contact", "Contact", "Home", null, 
                                                       new { @class = "list-group-item" })

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

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