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?

3

4 Answers 4

14

The built-in helper cannot do that.

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

Sign up to request clarification or add additional context in comments.

Comments

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>        }

Comments

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

Comments

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

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.