Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 550989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:20:47+00:00 2026-05-13T11:20:47+00:00

I know to use Html.ActionLink() to render textual <a href…> links to actions. How

  • 0

I know to use Html.ActionLink() to render textual <a href..."> links to actions.

How do I render a link to an action that has an underlying image as the link?

<a href="foo"><img src="asdfasdf"/></a>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:20:47+00:00Added an answer on May 13, 2026 at 11:20 am

    Here is code for the ImageLink HtmlHelper extension I use.

        /*
         * Image Link HTML helper
         */
    
        /// <summary>
        /// return image link
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="imageUrl">URL for image</param>
        /// <param name="controller">target controller name</param>
        /// <param name="action">target action name</param>
        /// <param name="linkText">anchor text</param>
        public static string ImageLink(this HtmlHelper helper, string imageUrl, string controller, string action, string linkText)
        {
            return ImageLink(helper, null, controller, action, linkText, imageUrl, null, null, null, null);
        }
    
        /// <summary>
        /// return image link
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="imageUrl">URL for image</param>
        /// <param name="controller">target controller name</param>
        /// <param name="action">target action name</param>
        /// <param name="linkText">anchor text</param>
        /// <param name="htmlAttributes">anchor attributes</param>
        public static string ImageLink(this HtmlHelper helper, string imageUrl, string controller, string action, string linkText, object htmlAttributes)
        {
            return ImageLink(helper, null, controller, action, linkText, imageUrl, null, null, new RouteValueDictionary(htmlAttributes), null);
        }
    
        /// <summary>
        /// return image link
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="imageUrl">URL for image</param>
        /// <param name="controller">target controller name</param>
        /// <param name="action">target action name</param>
        /// <param name="linkText">anchor text</param>
        /// <param name="htmlAttributes">anchor attributes</param>
        /// <param name="routeValues">route values</param>
        public static string ImageLink(this HtmlHelper helper, string imageUrl, string controller, string action, string linkText, object htmlAttributes, object routeValues)
        {
            return ImageLink(helper, null, controller, action, linkText, imageUrl, null, null, new RouteValueDictionary(htmlAttributes), new RouteValueDictionary(routeValues));
        }
    
        /// <summary>
        /// return image link
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="id">Id of link control</param>
        /// <param name="controller">target controller name</param>
        /// <param name="action">target action name</param>
        /// <param name="strOthers">other URL parts like querystring, etc</param>
        /// <param name="strImageURL">URL for image</param>
        /// <param name="alternateText">Alternate Text for the image</param>
        /// <param name="strStyle">style of the image like border properties, etc</param>
        /// <returns></returns>
        public static string ImageLink(this HtmlHelper helper, string id, string controller, string action, string linkText, string strImageURL, string alternateText, string strStyle)
        {
            return ImageLink(helper, id, controller, action, linkText, strImageURL, alternateText, strStyle, null, null);
        }
    
        /// <summary>
        /// return image link
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="id">Id of link control</param>
        /// <param name="controller">target controller name</param>
        /// <param name="action">target action name</param>
        /// <param name="linkText">anchor text</param>
        /// <param name="strImageURL">URL for image</param>
        /// <param name="alternateText">Alternate Text for the image</param>
        /// <param name="strStyle">style of the image like border properties, etc</param>
        /// <param name="htmlAttributes">html attribues for link</param>
        /// <returns></returns>
        public static string ImageLink(this HtmlHelper helper, string id, string controller, string action, string linkText, string strImageURL, string alternateText, string strStyle, IDictionary<string, object> htmlAttributes, RouteValueDictionary routeValues)
        {
            // Build the img tag
            TagBuilder image = new TagBuilder("img");
            image.MergeAttribute("src", strImageURL);
            image.MergeAttribute("alt", alternateText);
            image.MergeAttribute("valign", "middle");
            image.MergeAttribute("border", "none");
    
            TagBuilder span = new TagBuilder("span");
    
            // Create tag builder
            var anchor = new TagBuilder("a");
            var url = new UrlHelper(helper.ViewContext.RequestContext).Action(action, controller, routeValues);
    
            // Create valid id
            anchor.GenerateId(id);
    
            // Add attributes
            //anchor.MergeAttribute("href", "/" + controller + "/" + action); //form target URL
            anchor.MergeAttribute("href", url);
            anchor.MergeAttribute("class", "actionImage");
            if (htmlAttributes != null)
                anchor.MergeAttributes(new RouteValueDictionary(htmlAttributes));
    
            // place the img tag inside the anchor tag.
            if (String.IsNullOrEmpty(linkText))
            {
                anchor.InnerHtml = image.ToString(TagRenderMode.Normal);
            }
            else
            {
                span.InnerHtml = linkText;
                anchor.InnerHtml = image.ToString(TagRenderMode.Normal) + " " + span.ToString(TagRenderMode.Normal);
            }
    
            // Render tag
            return anchor.ToString(TagRenderMode.Normal); //to add </a> as end tag
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From my research, I know that I cannot use HTML input file to get
I know that ActiveMQ supports the JMSXUserID property: http://activemq.apache.org/jmsxuserid.html I'm trying to use Apollo
Does anyone know of a decent way to cleanly use Html.ActionLink helper with an
Folks, We are trying to use the strongly typed action link methods that look
I dont know how to use wireframesketcher in eclipse. http://wireframesketcher.com/install.html I've installed it, and
I have the following html and like to know how to use xpath to
I am new to MVC and know how to use Html.Displayfor() , but I
For setting that I use Html helper method which is not the best imo,
Is it possible to use HTML tags in the linkText of Html.ActionLink? For instance,
I use html's data- attribute on a list of menu links in order to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.