Twitter bootstrap MVC5 Razor-引导按钮类不工作

Twitter bootstrap MVC5 Razor-引导按钮类不工作,twitter-bootstrap,model-view-controller,razor,asp.net-mvc-5,Twitter Bootstrap,Model View Controller,Razor,Asp.net Mvc 5,我一直在尝试向我的按钮添加一个引导类,但它不起作用,我的按钮显示为一个简单的超链接 这是我当前的按钮: [@Html.ActionLink("Remove", "RemoveItem", new { id = item.ItemID, @class = "btn btn-warning btn-xs" }, new { d

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

这是我当前的按钮:

[@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?
                            })

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

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?"
  }
)

这就是克里斯在回答中所说的,并且打败了我

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

呈现的HTML是否在超链接上包含
class=“btn btn warning btn xs”
属性?