【问题标题】:MVC5 Razor - bootstrap button class not workingMVC5 Razor - 引导按钮类不起作用
【发布时间】:2016-06-04 01:11:51
【问题描述】:

我一直在尝试向我的按钮添加一个引导类,但它不起作用,我的按钮显示为一个简单的超链接

这是我目前拥有的按钮:

[@Html.ActionLink("Remove", "RemoveItem", new { id = item.ItemID, @class = "btn btn-warning btn-xs" },
                            new
                            {
                                data_confirmprompt = "Are you sure you want to delete this?
                            })

【问题讨论】:

  • 您呈现的 HTML 是否在超链接上包含 class="btn btn-warning btn-xs" 属性?

标签: twitter-bootstrap model-view-controller razor asp.net-mvc-5


【解决方案1】:

这是您在代码中调用的函数:

public static MvcHtmlString ActionLink(
  this HtmlHelper htmlHelper,
  string linkText,
  string actionName,
  object routeValues,
  object htmlAttributes);

所以,这应该是你要找的:

@Html.ActionLink(
  "Remove",       // The hyperlink text
  "RemoveItem",   // The controller name
  null,           // The annoymous type for route parameters
  new             // The annoymous type for HTML attributes
  {
    id = item.ItemID,
    @class = "btn btn-warning btn-xs",
    data_confirmprompt = "Are you sure you want to delete this?"
  }
)

这就是克里斯在他的回答中所说的并击败了我!

【讨论】:

    【解决方案2】:

    您在错误的匿名对象中传递了类属性。您在方法调用中拥有的第一个匿名对象对应于routeValues 参数,而第二个是htmlAttributes。将@class 位移动到第二个对象,应该没问题。

    【讨论】:

      猜你喜欢
      • 2016-06-19
      • 2014-08-17
      • 2018-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-12
      • 2015-10-12
      相关资源
      最近更新 更多