ASP.NET MVC 3 ValidateRequest(false) 不适用于 FormCollection [英] ASP.NET MVC 3 ValidateRequest(false) not working with FormCollection
问题描述
仅供参考,我使用的是 .NET 4.0/MVC 3.
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)
当我不输入 HTML 时一切正常,所以我知道正在触发正确的控制器.另外,我在 web.config 文件中正确设置了以下内容:
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"/>
只有当我包含 FormCollection(这个特定控制器需要它)时才会遇到这个问题.那么我到底做错了什么?
I only get this problem when I include the FormCollection (which is needed for this particular Controller). So what exactly am I doing wrong?
[我已经完成了对以下问题的建议,只要没有 FormCollection,它们就可以工作.他们都没有提供包含 FormCollection 的解决方案]
[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]
推荐答案
我想我已经解决了我自己的谜语,在这个论坛的帮助下:http://forums.asp.net/p/1621677/4163625.aspx
I think I've solved my own riddle, with the help of this forum: http://forums.asp.net/p/1621677/4163625.aspx
我只是修改了我的控制器,使其不接受控制器,而是从请求中获取未经验证的表单集合 [在 System.Web.Helpers 的帮助下].
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);
这篇关于ASP.NET MVC 3 ValidateRequest(false) 不适用于 FormCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!