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

后端 未结 3 1775
轻奢々
轻奢々 2020-12-03 17:07

FYI I am using .NET 4.0 / MVC 3.

In my controller, the following is my code:

[HttpPost]
[ValidateInput(false)]
public ViewResult Edit(ContentTemplate         


        
相关标签:
3条回答
  • 2020-12-03 17:44

    If you are using custom model binders and [ValidateInput(false)] is not working then you might find a solution here: http://blogs.taiga.nl/martijn/2011/09/29/custom-model-binders-and-request-validation/

    0 讨论(0)
  • 2020-12-03 17:46

    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);
    
    0 讨论(0)
  • 2020-12-03 17:58

    I just installed ASP.NET MVC 3 RC2, and this bug has been fixed. The following code works as expected now.

    [HttpPost]
    [ValidateInput(false)]
    public ViewResult Edit(FormCollection form)
    {
    }
    
    0 讨论(0)
提交回复
热议问题