绑定前编辑Request.Form
有没有办法在操作方法绑定到参数之前编辑Request.Form? 我已经有一个反射调用来启用 Request.Form 的编辑。 我只是找不到可以在绑定发生之前更改它的扩展点。
更新:看起来我正在编辑 Request.Form 但没有意识到。 我通过查看绑定参数进行验证。 这是不正确的,因为当您到达 ActionFilter 时,表单值已被复制/设置到 ValueProvider 中。 我相信这是提取值进行绑定的地方。
因此,问题就变成了在绑定表单值之前对表单值应用一些过滤的最佳方法是什么。 我仍然希望发生绑定。 我只想编辑它用于绑定的值。
Is there a way to edit the Request.Form before the action method binds to the parameters? I already have a reflection call to enable editing of Request.Form. I just can't find a point of extensibilty where I can alter it before binding occurs.
UPDATE: So it looks like I was editing the Request.Form and didn't realize it. I was verifying by looking at the bound parameters. That is incorrect b/c by the time you get to the ActionFilter the form values have already been copied/set to/in the ValueProvider. Which I believe is where the values are pulled for binding.
So the question becomes what is the best way to apply some filtering to the form values before they are bound. I still want the binding to occur. I just want to edit the values it uses to bind.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建自定义过滤器并覆盖
OnActionExecuting()
:或者只需在控制器中覆盖
OnActionExecuting()
更新:
Create custom filter and override
OnActionExecuting()
:Or simply override
OnActionExecuting()
in your controllerUPDATED:
我最终扩展了 DefaultModelBinder 上的 SetProperty 方法,以在继续基本行为之前检查该值。 如果该值是字符串,我将执行过滤。
I ended up extending the SetProperty method on the DefaultModelBinder to check the value before proceeding with the base behavior. If the value is a string I perform my filtering.