0

I'm currently using MVC 3 (WebForm view engine) and have a form that shows user comments.

If I have a comment which has an ampersand (&), <%= Html.Textbox() %> will encode it as &amp;. However, if the form is then posted to the server, ASP.NET kicks in thinking that the submitted content is malicious.

I find myself having to use HTML decoding methods using JavaScript before the content is sent to the server.

I am able to get the results that I want, but I feel like I'm not doing this right.

Any suggestions?

Community
  • 1
  • 1
Andy T
  • 10,223
  • 5
  • 53
  • 95

1 Answers1

0

You can use special attribute to allow safe html tags to be posted by using AllowHtml attribute , you will define your model/viewmodel as following

public class Comment
{

       public int Id{get; set;}

       [AllowHtml] // Allow safe html tags
       public string Comment {get; set;}   
}
Nadeem Khedr
  • 5,273
  • 3
  • 30
  • 37