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
  • 12,622
  • 16
  • 73
  • 101
Suraj
  • 407
  • 1
  • 8
  • 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
  • 101,612
  • 66
  • 270
  • 352
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
  • 7,046
  • 1
  • 32
  • 46
0

Use this

<a href="<%: Url.Action("Action", "Controller")%>"><img src="yourimg.jpg" /></a>
TechGuy
  • 4,298
  • 15
  • 56
  • 87
0

Use @Url.Action on Razor :

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