Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make html.actionlink without text but with image inside

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??

like image 703
r.r Avatar asked Sep 14 '10 07:09

r.r


1 Answers

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).

like image 112
Fenton Avatar answered Sep 23 '22 02:09

Fenton