使用html.ActionLink而不是HTML编码 [英] using html.ActionLink but not html encoding

查看:111
本文介绍了使用html.ActionLink而不是HTML编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想返回以下输出

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

如果我做了以下的内容是HTML EN codeD。

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

我如何禁用HTML编码?

How can i disable the html encoding?

推荐答案

您可以创建一个的HtmlHelper这种

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);
    }
}

在的.aspx:

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

这篇关于使用html.ActionLink而不是HTML编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆