【问题标题】:MVC3 TextArea issue with HTML renderingHTML 渲染的 MVC3 TextArea 问题
【发布时间】:2012-08-31 14:43:02
【问题描述】:

我有一个 C# MVC3 .Net Web 应用程序。我有几个 TextArea 控件。它们包含从我们的数据库填充的 HTML 字符串。一些 TextArea 控件是 CkEditor,它们工作正常。他们有一个名为“htmlEncodeOutput”的属性。这避免了 ASP.NET 安全问题。当我导航到一个新页面时,标准的 TextAreas 令人讨厌。我相信这是由于嵌入的 HTML。我可以设置 TextAreas 的属性来对嵌入的 HTML 进行编码吗?

这是抛出的错误:

A potentially dangerous Request.Form value was detected from the client (item.SowDescription="...; it sodas<br />
<strong><em>...").

【问题讨论】:

  • 需要更多解释以了解确切的问题是什么?
  • 如果您包含实际遇到的异常可能会有所帮助。
  • 这会有所帮助。它抛出异常“不在 UnitoFWork 中”。但这不是问题。我认为这是一种副作用。

标签: html asp.net-mvc-3 render encode


【解决方案1】:

我想通了。在文本区域中,我使用 HttpUtility.HtmlDecode 来呈现正在呈现的属性。示例如下:

<textarea rows="3" cols="33" class="readonly"
            readonly="readonly" 
            id = "@Id">
    @HttpUtility.HtmlDecode(item.Description)
</textarea>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-10
    • 2014-07-11
    • 2022-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多