是否有一个ASP.NET MVC的HtmlHelper图像链接?

问题描述:

该Html.RouteLink()的HtmlHelper的伟大工程的文字链接。但是,什么是一个图像链接的最佳方式?

The Html.RouteLink() HtmlHelper works great for text links. But what's the best way to link an image?

在这里我的,它的核心功能做一些重载

here mine, its the core function make some overloads

 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();

    }