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.
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).
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.
There is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.
Use @Url.Action
instead:
<a href='@Url.Action("Index", "Home")'>
<img src="IMAGE PATH HERE" />
</a>
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"});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With