Search code examples
asp.net-mvc-3html-encode

MVC3 C# Potentially dangerous request error


I have an MVC3 C#. Web App. One of our properties uses an RTF control for our TextBoxFor controls:

                @Html.TextAreaFor(model => model.SowDescription,
                    (object)new
                    {
                        rows = 7,
                        cols = 65,
                        @class = "celltext2 save-alert attachmentEditor",
                        disabled = "disabled"
                    } 

THe attachmentEditor class uses CkEditor. So there are html tags embedded in the control for Bold, Italics, etc. A user pasted some data into this TextArea and we received this error:

A potentially dangerous Request.Form value was detected from the client (SowDescription="<br />  <br />  <u><..."). ******** 

We use HttpUtility.HtmlDecode in other cases, but the using it in the Html.TextAreFor() helper we get this error:

Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

Any ideas how we can Encode/Decode the using the Html.TextAreaFor() helper?


Solution

  • Try decorating the SowDescription viewmodel property with the [AllowHtml] attribute.