0

I wish to return the following output

<a href="#"><img src="/images/icons/tick.png" alt="" />More info</a>

If i do the following the content is html encoded.

<%= Html.ActionLink("<img src='/images/icons/tick.png' />More info", "OrderRegion", "Campaign", new {id = Model.Campaign.Id}, null) %>

How can i disable the html encoding?

1
  • Your code does not match your output. Your output uses just # for URL whereas your code implies you want a URL to an Action. Commented Oct 19, 2010 at 15:13

3 Answers 3

6

I think you are better off using Url.Action here, e.g.:

<a href="<%= Url.Action("OrderRegion", "Campaign", new {id = Model.Campaign.Id}) %>">
    <img src="/images/icons/tick.png" alt="" />More info
</a> 
Sign up to request clarification or add additional context in comments.

Comments

3

you can create an HtmlHelper to this

public static class HtmlHelpers
{
    public static string MyActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)
    {
        var tagActionLink = htmlHelper.ActionLink("[replace]", actionName, controllerName, routeValues, htmlAttributes).ToHtmlString();
        return tagActionLink.Replace("[replace]", linkText);
    }
}

in .aspx:

<%= Html.MyActionLink("<img src='/images/icons/tick.png' />More info", "OrderRegion", "Campaign", new {id = 15}, null) %>

3 Comments

You should use a TagBuilder.
Is it possible to do something like this, but using an Ajax.ActionLink?
If you're having trouble finding ActionLink method on the HtmlHelper class, it's an extension method and can be found by adding a using System.Web.Mvc.Html; statement.
0

If you are building an MvcHtmlString and want to include a helper-styled absolute path, you can use

VirtualPathUtility.ToAbsolute("~/")

and then append your link text, controller, and actions with fancy HTML/entites as string literals in the MvcHtmlString construction.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.