mvc3 Html.ActionLink as image not as text

2019-06-21 23:19发布

问题:

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

回答1:

The built-in helper cannot do that.

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



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


回答3:

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



回答4:

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