Search code examples
asp.netasp.net-mvctwitter-bootstraptwitter-bootstrap-3glyphicons

How to replace actionlink text with a glyphicon in @Html.ActionLink?


I want to replace X with glyphicon-trash.

I am using X as a linktext.Which works for deleting an item.How to replace with a glyphicon.

Here is my code

 @Html.ActionLink(
                     "X",
                     "Delete",
                     "Grocery",
                     new { GroceryUsageID = item.GroceryUsageID, GroceryId = item.GroceryID },
                     new { @onclick = "return confirm('Are you sure you want to delete this Grocery');"})

Solution

  • You can do it like following. Just add @class = "glyphicon glyphicon-trash" in htmlAttributes parameter and replace X with a space.

     @Html.ActionLink(
            " ",
            "Delete",
            "Grocery",
            new { GroceryUsageID = item.GroceryUsageID, GroceryId = item.GroceryID },
            new { @onclick = "return confirm('Are you sure you want to delete this Grocery');", 
                  @class = "glyphicon glyphicon-trash" })