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.

1

4 Answers 4

18

Use @Url.Action instead:

<a href='@Url.Action("Index", "Home")'>
   <img src="IMAGE PATH HERE" />
</a>
Sign up to request clarification or add additional context in comments.

Comments

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"});

Comments

0

Use this

<a href="<%: Url.Action("Action", "Controller")%>"><img src="yourimg.jpg" /></a>

1 Comment

This is correct, except for the escaping tags. MVC 4 uses the @ nugget.
0

Use @Url.Action on Razor :

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.