views:

101

answers:

2

it is simple html:

<%--
<a href="?language=de">
    <img src="/Images/Company/de.png" alt="Webseite auf Deutsch" style="border: 0;" />
</a>
--%>

i would like to make from them html.actionlink:

 <%= Html.ActionLink("", "ChangeCulture", "Account", new { lang = "de", returnUrl = this.Request.RawUrl }, new { @style = "background-image: url(/Images/Company/de.png)", @class = "languageLink" }) %>

I would like to have my link without text. it doesn't work, null in a first parameter its not allowed. image is to short as normal. how can i use html.actionlink without text but with image??

+1  A: 

Here is a solution.

<a href="<%= Url.RouteUrl("MyRoute", new { id = Model.Id }) %>">
   <img src="myimage.png" alt="My Image" />.
</a>

Essentially, ActionLink is for text links and there isn't an equivalent for images, but you can use Url.RouteUrl to get the address for the link and put any HTML code you like inside of the anchor (W3C permitting of course).

Sohnee
+1  A: 

based on a previous SO question (that was closed), here's a solution:

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

the orignal can be found here: http://stackoverflow.com/questions/675319/is-there-an-asp-net-mvc-htmlhelper-for-image-links

jim