在HTML操作链接中创建带有图标的按钮

时间:2018-10-24 06:47:21

标签: c# asp.net-mvc

是否可以在HTML操作链接上放置一些图标或创建一个按钮,因为当前我只有一个带有超链接的纯文本:

这是我的代码:

@Html.ActionLink(
                            "Remove",
                            "Delete",
                            new { id = item.name},
                            new { onclick = "return confirm('Are you sure you want to remove "+ @item.name +" to list ?');" })  

4 个答案:

答案 0 :(得分:1)

可以使用Bootstrap CSS选择器将图标添加到ActionLink帮助器中。由于操作目的是删除数据,因此您的按钮应具有与链接关联的CSS选择器glyphicon-trash

@Html.ActionLink("Remove", "Delete", new { id = item.name },
                  new { @class = "glyphicon glyphicon-trash", 
                  onclick = "return confirm('Are you sure you want to remove "+ @item.name +" to list ?');" })  

答案 1 :(得分:0)

您可以像这样对图标使用class

  @Html.ActionLink("action", "controller", new { id = yourid }, new { @title = "Edit", @class = "glyphicon glyphicon-pencil" })

答案 2 :(得分:0)

@Html.ActionLink("Remove","Delete", new { id = item.name}, new { @class = "glyphicon glyphicon-search", @tabindex = "20" }, new { onclick = "return confirm('Are you sure you want to remove "+ @item.name +" to list ?');" })

答案 3 :(得分:0)

您可以简单地将CSS类应用于htmlAttributes对象。

<%= Html.ActionLink("Button Name", "Index", null, new { @class="classname" }) %>

,然后在样式表中创建一个类

a.classname
{
    background: url(../Images/image.gif) no-repeat top left;
     display: block;
     width: 150px;
     height: 150px;
     text-indent: -9999px; /* hides the link text */
}