K.Z
K.Z

Reputation: 5075

use icon in ActionLink for ASP.NET MVC, Razor Page

i am trying to print icon in actionLink in Razor code but it is not happening... I am using actionLink with action-Name and controller with the class and use this class in css to print icon.... i don't know where i am doing mistake ???

I am getting following line in page source;

 <a class="CreateNewEntry_Icon" href="/Qualification/CreateNewFreeZone?Length=13">New FreeZone</a>

My Code

public ActionResult CreateNewFreeZone()
    {
        return PartialView("Partial_CreateNewFreeZone");
    }


@Html.ActionLink("New FreeZone", "CreateNewFreeZone", "Qualification", new { @class = "CreateNewEntry_Icon" })

CSS:

.CreateNewEntry_Icon {
    width:24px;
    height:24px;
    background:url("~/ImagesAndIcons/Icons/Add_New.png") no-repeat;

}

Upvotes: 2

Views: 3630

Answers (2)

hutchonoid
hutchonoid

Reputation: 33306

You need this instead:

@Html.ActionLink("New FreeZone", "CreateNewFreeZone", "Qualification", null, new { @class = "CreateNewEntry_Icon" })

Your original is passing the class to the routeValues instead of the htmlAttributes parameter.

Adding the extra parameter, null in this case results in the correct overload being called which takes the htmlAttributes as the last parameter.

Upvotes: 2

Nilesh Gajare
Nilesh Gajare

Reputation: 6398

Try this

@Html.ActionLink("New FreeZone", "CreateNewFreeZone", "Qualification", new{ }, new { @class = "CreateNewEntry_Icon" })

Upvotes: 1

Related Questions