I am using jquery.cleditor.js
plugin for html editor in my mvc application and it is working fine. Now I want to post the editor value to controller action but here I am getting the following exception:
A potentially dangerous Request.Form value was detected from the client
(NewContentPage.PageContents="<STRONG>dafs </STRON...").
If someone has idea then, please guide me to do this.
If you add ValidateInput
attribute with false
it will allow you to submit HTML. Just be aware that you are turning of validation for all of the properties in the viewModel
[HttpPost, ValidateInput(false)]
public ActionResult DoStuff(MyViewModel viewModel)
{
//...
}
If you are using .NET 4 you'll also have to set <httpRuntime requestValidationMode="2.0" />
in your web.config file.
If you are using MVC 3 you don't have to add the ValidateInput
attribute to the controller action you can add AllowHtml
attribute to the property in the viewModel.
public class MyViewModel
{
public string prop1 { get; set; }
[AllowHtml]
public string prop2 { get; set; }
}
This allows HTML for prop2
but the rest of the MyViewModel
will be validated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With