【问题标题】:Html.Raw(HttpUtility.HtmlDecode(item.Content)) displays html tagsHtml.Raw(HttpUtility.HtmlDecode(item.Content)) 显示html标签
【发布时间】:2013-09-11 19:35:54
【问题描述】:

我在 asp.net mvc4 应用程序中使用 tinyMce。我设法通过为 tinyMce textarea 设置 encoding:"xml" 将 textarea 的内容保存到数据库中。但是我无法使用以下方法显示原始 html:

  @Html.Raw(HttpUtility.HtmlDecode(item.Content))

它仍然在文本中显示 html 标签。有人可以帮我只显示内容,这样html标签就不会被“转义”。

提前谢谢你

【问题讨论】:

    标签: html asp.net asp.net-mvc-4 tags tinymce


    【解决方案1】:

    我会查看您的数据。我遇到了类似的事情,发现我的数据是用 ascii 标签保存的。编辑器正在翻译这些 ascii 标签并显示 html 标签而不是渲染。我创建了两种简单的转换方法

    public string Decode(string value)
        {
            return (value)
                .Replace(""", "\"")
                .Replace("&lt;", "<")
                .Replace("&gt;", ">");
        }
    
        public string Encode(string value)
        {
            return (value)
              .Replace("\"", "&quot;")
              .Replace("'", "''")
              .Replace("<", "&lt;")
              .Replace(">", "&gt;");
        }
    

    然后将我的字符串运行到​​数据库并返回,它为我解决了问题。

    【讨论】:

    • 感谢您的回答,经过很长一段时间后,我发现我用 tinyMce 和 C# 控制器对内容进行了一次编码,所以我对其进行了双重编码,所以这是我的问题。正如你所说,我的数据是用 ascii 标签保存的
    猜你喜欢
    • 2019-02-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-24
    • 1970-01-01
    • 2023-01-24
    • 2023-03-13
    • 2016-04-05
    • 2021-11-16
    相关资源
    最近更新 更多