【问题标题】:mvc3 Html.ActionLink as image not as textmvc3 Html.ActionLink 作为图像而不是文本
【发布时间】:2012-01-16 04:58:40
【问题描述】:
<div class="orderby_name">
@Html.ActionLink(" ", "DisplayCategory", "Categories", new { articleSortBy = "Name", articleSortType = "asc" }, null)
</div>

如果存在 ImageLink,我正在寻找剃刀。现在我有了@Html.ActionLink,因为我没有任何文本名称,我无法点击它。我想要图片作为链接。

如何将图像作为剃须刀中的链接?

【问题讨论】:

标签: asp.net-mvc-3


【解决方案1】:

内置助手无法做到这一点。

你需要创建一个普通的&lt;a href="@Url.Action(...)"&gt;标签。

【讨论】:

    【解决方案2】:

    希望此代码对您有所帮助

    @using (Html.BeginForm())
                    {
                        <a href='@Url.Action("Index")'>
                            <img src='@Url.Content("../../Content/Images/head.jpg")' alt="Home Page">
                        </a>        }
    

    【讨论】:

      【解决方案3】:

      实际上看起来有一种方法..如果您将CSS规则添加到htmlAttributes,如本文的顶部答案所示: Html.ActionLink as a button or an image, not a link

      【讨论】:

        【解决方案4】:

        在 asp.net mvc 3 中,您的代码与链接文本的单个空格一起使用,只需添加一个指向图像的类名(下面的类名指向字体真棒图像):

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

        并添加一些 css 以防止图像有下划线:

        a.fa
        {
            text-decoration:none;
        }
        

        【讨论】:

          猜你喜欢
          • 2010-10-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-05-24
          • 1970-01-01
          相关资源
          最近更新 更多