Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 21, 2012 07:01 AM by CodeHobo
Apr 20, 2012 08:41 PM|LINK
I'm trying to use Html.AnchorLink to display an anchor link with an image inside and no text. I'm trying to pass the image tag in the first parameter of AnchorLink, the text parameter. My parameter begins "<img" and it comes out in the browser as "<img".
How can I do this? Is there an easier/better way to do this?
Apr 20, 2012 09:00 PM|LINK
I think you mean Html.ActionLink.
You can't pass html to the ActionLink Helper. It automatically html encodes the text (which is why your html comes out looking strange), that's actually a great security feature and protects against XSS attackys.
If you want to customize a link and add an image you have to construct the link using url.Action like so
<a href="@Url.Action("action","controller")"> <img src="/content/image.png" /> </a>
Edit: Url.Action takes the same input parameters you would pass to Html.ActionLink minus the actual text of the link.
Apr 21, 2012 03:20 AM|LINK
I'm trying to use Html.AnchorLink to display an anchor link
Do you have a custom extension?
Apr 21, 2012 03:57 AM|LINK
Apr 21, 2012 07:01 AM|LINK