It is necessary to make a picture, when clicking on which, the user moved to the desired .aspx page of another controller. Here is an example of a working link using ASP:

<%: Html.ActionLink ("Back to Home", "Index", "Home")%>

How to do the same, but that the link was not a text, but a picture? It is impossible to establish through the properties of the picture, since if there is a link to the aspx page, then the server markup is not generated

    2 answers 2

    It is possible so:

    <a href="<%= Url.Action("ActionName") %>"> <img src"/images/image.jpg" alt="" /> </a> 
    • Thank you - Jembo_by

    Such a problem is usually solved by writing your own html helper (via the extension method). For a picture, the link will look something like this:

    C # code:

      public static MvcHtmlString ActionLinkImage(this HtmlHelper helper, string src, string url, string cssClass, string title = "") { var href = new TagBuilder("a"); href.MergeAttribute("href", url); href.MergeAttribute("title", title); if (!string.IsNullOrEmpty(cssClass)) href.AddCssClass(cssClass); var img = new TagBuilder("img"); img.MergeAttribute("src", src); img.MergeAttribute("alt", title); href.InnerHtml = img.ToString(TagRenderMode.SelfClosing); return MvcHtmlString.Create(href.ToString(TagRenderMode.Normal)); } 

    In the code page then you will write:

    @ Html.ActionLinkImage (parameters) (or ASPX markup instead of Razor)

    Recheck the code did not test.

    The null solution also works well.

    • And without writing a helper in any way? Well, just write a whole helper for the sake of one simple procedure that can be easily done in plain HTML ... - Jembo_by
    • Then, since I wrote null. - yura-k
    • Yes, I just checked it out. It is clearly easier there, but thank you too! - Jembo_by