HTML呈现的MVC3 TextArea问题

时间:2012-09-06 18:02:10

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

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

这是抛出的错误:

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

1 个答案:

答案 0 :(得分:0)

我明白了。在文本区域中,我使用HttpUtility.HtmlDecode来渲染属性。示例如下:

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