user7090664
user7090664

Reputation: 45

How Can I add a class to an HTML.ActionLink in MVC?

I have html code which is posted below. I would like to apply that Delete and Edit Button class to HTML Action Link.

Here is my code.

@Html.ActionLink("Edit", "EditUser", new { UserName = item.UserName }) |
                        @if ((item.UserName.ToLower() != this.User.Identity.Name.ToLower()))
                            {
                            @Html.ActionLink("Delete", "DeleteUser", new { UserName = item.UserName },
                new { onclick = "return confirm('Are you sure you wish to delete this user?');" })
                        }

This HTML Code for Delete and Edit:

<a href="#" class="btn btn-info btn-xs black">
    <i class="fa fa-trash-o"></i> Delete
</a>
<a href="#" class="btn btn-success btn-xs purple">
    <i class="fa fa-edit"></i> Edit
</a>

How can I make it work?

Help would be appreciated.

Upvotes: 0

Views: 334

Answers (1)

longnx1986
longnx1986

Reputation: 21

You have to use the @ character, since class is a keyword in C#. Here's a link to the MSDN documentation: http://msdn.microsoft.com/en-us/library/dd492124(v=vs.108).aspx

@Html.ActionLink("<i class='fa fa-trash-o'></i> Delete", "DeleteUser",
     new { UserName = item.UserName },
     new { @class = "btn btn-info btn-xs black" })

Upvotes: 1

Related Questions