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>
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>
If you are on ASP.Net MVC 1.0 you can get the futures library and do this:
You just need to add this library: Microsoft.Web.Mvc download the dll here
This is also supposed to be part of ASP.Net MVC 2.0 at some point.
I have tested the
ImageLink
helpers and suggest that they should be made to returnMvcHtmlString
instead ofstring
to prevent the Razor engine from encoding the actual image URLs.So I changed all the signatures of the ImageLink functions to return 'MvcHtmlString' instead of plain 'string' and changed the last line of the last version of 'ImageLink' to:
Here is code for the ImageLink HtmlHelper extension I use.
Two options I can think of, I'll give you the suggested one first:
One: Give the anchor an a unique ID and use CSS to style the link appropriately. This will also give you the ability to easily apply a rollover image using :hover.
Two: Create your own HtmlHelper that either doesn't escape the linkText parameter like ActionLink does or takes an image URL.
Check here for how to create the Image method
Alternately, just write it in:
Here is a post about creating strongly typed ActionImage extensions. Should get you started if you don't like those horrible error-prone magic strings.