7

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.

Max
  • 11,885
  • 15
  • 70
  • 96
Suraj
  • 377
  • 1
  • 7
  • 12
  • possible duplicate of [How to make a actionlink as Image in Asp.Net MVC4 Razpr View?](http://stackoverflow.com/questions/22007291/how-to-make-a-actionlink-as-image-in-asp-net-mvc4-razpr-view) – Rajesh Dhiman Mar 07 '14 at 10:42

4 Answers4

18

Use @Url.Action instead:

<a href='@Url.Action("Index", "Home")'>
   <img src="IMAGE PATH HERE" />
</a>
Community
  • 1
  • 1
Curtis
  • 98,395
  • 62
  • 265
  • 345
2

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"});
NinjaNye
  • 6,828
  • 1
  • 32
  • 45
0

Use this

<a href="<%: Url.Action("Action", "Controller")%>"><img src="yourimg.jpg" /></a>
TechGuy
  • 3,939
  • 13
  • 50
  • 78
0

Use @Url.Action on Razor :

 <img src="@Url.Action("ActionName", "ControlName", new { Model.ImageId })" />
Bravo Hex
  • 1
  • 1
  • 1