加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 是否有一个ASP.NET MVC HtmlHelper的图像链接?

发布时间:2020-12-15 23:50:43 所属栏目:asp.Net 来源:网络整理
导读:Html.RouteLink()HtmlHelper适用于文本链接.但是,连接图像的最佳方式是什么? 解决方法 这里是我的,它的核心功能使一些重载 public static string ImageLink(this HtmlHelper htmlHelper,string imgSrc,string alt,string actionName,string controllerName,
Html.RouteLink()HtmlHelper适用于文本链接.但是,连接图像的最佳方式是什么?

解决方法

这里是我的,它的核心功能使一些重载
public static string ImageLink(this HtmlHelper htmlHelper,string imgSrc,string alt,string actionName,string controllerName,object routeValues,object htmlAttributes,object imgHtmlAttributes)
    {
        UrlHelper urlHelper = ((Controller)htmlHelper.ViewContext.Controller).Url;
        string imgtag = htmlHelper.Image(imgSrc,alt,imgHtmlAttributes);
        string url = urlHelper.Action(actionName,controllerName,routeValues);



        TagBuilder imglink = new TagBuilder("a");
        imglink.MergeAttribute("href",url);
        imglink.InnerHtml =imgtag;
        imglink.MergeAttributes(new RouteValueDictionary(htmlAttributes),true);

        return imglink.ToString();

    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读