开发者

using html.ActionLink but not html encoding

I wish to return the following output

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

If i do the following th开发者_开发知识库e 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?


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> 


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜