Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC 3 ValidateRequest(false) not working with FormCollection

FYI I am using .NET 4.0 / MVC 3.

In my controller, the following is my code:

[HttpPost]
[ValidateInput(false)]
public ViewResult Edit(ContentTemplateView contentTemplateView, FormCollection collection)

Everything works fine when I don't enter HTML, so I know the proper controller is being fired. Also, I have following set properly in my web.config files:

<httpRuntime requestValidationMode="2.0"/>

I only get this problem when I include the FormCollection (which is needed for this particular Controller). So what exactly am I doing wrong?

[I have done what was proposed on the following questions, and they work as long as there is no FormCollection. None of them offer a solution with an included FormCollection]

  • Why is ValidateInput(False) not working?
  • Asp.Net MVC Input Validation still firing after being disabled
  • ValidateInput Attribute Doesn't Seem To Work in ASP.NET MVC
like image 426
dochoffiday Avatar asked Dec 05 '10 23:12

dochoffiday


1 Answers

I think I've solved my own riddle, with the help of this forum: http://forums.asp.net/p/1621677/4163625.aspx

I just modified my Controller so that it didn't accept the Controller, and instead grabbed the unvalidated form collection from the Request [with the help of System.Web.Helpers].

using System.Web.Helpers;

[HttpPost]
[ValidateInput(false)]
public ViewResult Edit(ContentTemplateView contentTemplateView)
{
    FormCollection collection = new FormCollection(Request.Unvalidated.Form);
like image 173
dochoffiday Avatar answered Oct 02 '22 04:10

dochoffiday