5
<div class="orderby_name">
@Html.ActionLink(" ", "DisplayCategory", "Categories", new { articleSortBy = "Name", articleSortType = "asc" }, null)
</div>

i am lookin in razor if exist ImageLink. Now i have @Html.ActionLink and becouse i do not have any text name i can not click on it. I want to have image as link.

How can i make image as link in razor?

senzacionale
  • 20,448
  • 67
  • 204
  • 316
  • You have to create custom helper. Try this here: http://stackoverflow.com/questions/5111110/mvc3-actionlink-with-images-but-without-mvcfutures – bobek Dec 08 '11 at 19:20
  • Here is an example of what you are looking for: http://stackoverflow.com/questions/4896439/action-image-mvc3-razor – Shawn Dec 08 '11 at 19:23
  • possible duplicate of [Html.ActionLink as a button or an image, not a link](http://stackoverflow.com/questions/596444/html-actionlink-as-a-button-or-an-image-not-a-link) – Bertrand Marron Dec 08 '11 at 19:29

4 Answers4

14

The built-in helper cannot do that.

You need to create an ordinary <a href="@Url.Action(...)"> tag.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
2

Hope this code is helpful

@using (Html.BeginForm())
                {
                    <a href='@Url.Action("Index")'>
                        <img src='@Url.Content("../../Content/Images/head.jpg")' alt="Home Page">
                    </a>        }
Saroop Trivedi
  • 2,245
  • 6
  • 31
  • 49
1

In asp.net mvc 3 the code you have works with the single space for the link text, just add a class name that points to an image (the class name below points to a font awesome image):

@Html.ActionLink(" ", "ActionName", "ControllerName",
new {UniqueId = item.UniqueId},
new { @class = "fa fa-download", @title = "Download the document" })

And add some css to prevent the image from having an underline:

a.fa
{
    text-decoration:none;
}
Tom Regan
  • 3,580
  • 4
  • 42
  • 71
1

Actually it looks like there is a way.. if you add a CSS rule to the htmlAttributes, as is shown in the top answer of this post: Html.ActionLink as a button or an image, not a link

Community
  • 1
  • 1
dizzwave
  • 4,013
  • 1
  • 19
  • 16