views:

412

answers:

3

In one of our ASP.NET MVC application we are using FCKEditor to allow users to enter rich text. In order to turn off the validation in the controller actions we set the attribute

[ValidateInput(false)]

Users are able to save and modify the rich text as long as there are no business validation errors in the page.

If any of the business validations fail and the ModelState.IsValid is set to false, on rendering the page the following exception is raised. Can someone let me know how to solve this issue?

A potentially dangerous Request.Form value was detected from the client (Programme_Overview="

Here is the code

    [ValidateInput(false)]
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Schedule(FormCollection formValues)
    {
      // some code
      if (ModelState.IsValid)
        {
            //do something here...
        }
        else
        {               
            return View(programDetails);
        }


     }

    //// View code that render the fckeditor text area
    <%= Html.TextArea("Programme_Overview", Model.Programme.Overview, new { row = 7 })%>
A: 

It is likely some HTML output from your fuckeditor gets somehow submitted.

You can try to switch the validation off:

public MyController
{
    [ValidateInput (false)]
    public ActionResult MyAction ()
    {
    }
}
User
A: 

Just add the following to your action:

[ValidateInput(false)]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SomeAction() {}
Darin Dimitrov
Even after specifying [ValidateInput(false)], the exception is raised if ModelState.IsValid is set to false while rendering the view
Gopinath
Could you show us your action method and the html form?
Darin Dimitrov
darin, i updated the question with code.
Gopinath
A: 

I'm guessing this project was migrated from a pre-1.0 RTM project.

Original ASP.NET has page-level "dangerous input" validation that you're tripping up. We have turned it off system-wide with a change to the Web.config file in the Views folder, but I don't remember exactly when we made that change. If your project pre-dates this change, then you won't have that setting in your Web.config file in the Views folder.

So you can make a new MVC project and look at the Web.config file to see what setting(s) you might want to copy over. You can also disable this on a page-by-page basis if you want.

http://www.asp.net/learn/whitepapers/request-validation/

Brad Wilson
Brad Wilson,I'm not sure what version of MVC we have. Can you please tell me how to find it on my PC?We installed MVC with the help of Web Installer 2 months ago. The web.config file located in the View folder has <pages validateRequest="false" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
Gopinath
You have 1.0 installed, and I see the validatedRequest="false" line is there, so I'm not clear why you should be hitting this error (unless you've added "validateRequest=true" to the <%@ Page %> directive in your actual page).
Brad Wilson