Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add an image in @Html.ActionLink

I need to know how to add a image in @Html.ActionLink

The code I have is:

@Html.ActionLink("IMAGE","Index","Home"); 

How to replace the IMAGE with an URL where my image is residing.

like image 227
Suraj Avatar asked Mar 07 '14 10:03

Suraj


People also ask

How do I pass an object in ActionLink?

If you need to pass through the reference to an object that is stored on the server, then try setting a parameter of the link to give a reference to the object stored on the server, that can then be retrieved by the action (example, the Id of the menuItem in question).

What is HTML ActionLink ()?

Html. ActionLink creates a hyperlink on a view page and the user clicks it to navigate to a new URL. It does not link to a view directly, rather it links to a controller's action.

What is difference between HTML ActionLink and URL action?

There is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.


2 Answers

Use @Url.Action instead:

<a href='@Url.Action("Index", "Home")'>
   <img src="IMAGE PATH HERE" />
</a>
like image 71
Curtis Avatar answered Sep 21 '22 10:09

Curtis


You have one of 2 options

<a href="@Url.Action("Index", "Home")" >
    <img src="IMAGE" />
</a>

OR add a class and use the class to define the image

@Html.Action("Text", "Index", "Home", new {Class = "image-link"});
like image 39
NinjaNye Avatar answered Sep 23 '22 10:09

NinjaNye