MVC 3 RTM.拥有一个具有AllowHtml属性的模型.在我的控制器操作中,如果操作将FormCollection作为参数,则会抛出异常:
[HttpPost]
public ActionResult Edit(FormCollection collection, int id)
{
var myEntity = _myRepo.Get(id);
TryUpdateModel(myEntity);
return DoSave(myEntity);
}
Run Code Online (Sandbox Code Playgroud)
从客户端检测到潜在危险的Request.Form值
但是,如果我的控制器操作使用对象而不是FormCollection,则它不会抛出异常.
[HttpPost]
public ActionResult Edit(MyEntity postedEntity, int id)
{
var myEntity = _myRepo.Get(id);
TryUpdateModel(myEntity);
return DoSave(myEntity);
}
Run Code Online (Sandbox Code Playgroud)
我已经设置好了
httpRuntime requestValidationMode ="2.0"
使用FormCollection时为什么会失败?