里面ActionFilter型号的可用性 [英] Model availability inside ActionFilter

查看:185
本文介绍了里面ActionFilter型号的可用性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了我要创建一个ASP.NET MVC应用程序的新ActionFilter。我有一个接受一个HTTP POST和操作方法的参数的动作接受一个对象,我创建并注册自定义模型粘合剂。

I have created a new ActionFilter for an ASP.NET MVC application that I'm creating. I have an action which accepts an Http Post and the argument of the action method accepts an object, for which I have created and registered a custom model binder.

我注意到,里面的 IActionFilter.OnActionExecuting filterContext.Controller.ViewData.Model 总是值尽管它看起来像模型绑定的动作过滤器 OnActionExecuting 方法之前总是调用。与此相反,在 IActionFilter.OnActionExecuted 相同的动作过滤器的方法的值 filterContext.Controller.ViewData.Model 不为null。

I noticed that inside the IActionFilter.OnActionExecuting the value for filterContext.Controller.ViewData.Model is always null despite the fact that it looks like the model binder is always invoked before the action filter OnActionExecuting method. In contrast to this inside the IActionFilter.OnActionExecuted method of the same action filter the value for filterContext.Controller.ViewData.Model is not null.

你们是否知道这是通过设计或一个错误?如果设计的是他们这说明为什么这是任何链接?谢谢你。

Do you guys know if this is by design or a bug? If by design are their any links which describe why this is? Thanks.

推荐答案

由于控制器动作负责创建模型并将其传递给视图怎么可能之前被称为动作模型存在吗?你不知道是什么型号下去,直到完事后要创建。

Since the Controller Action is responsible for creating the Model and passing it to the View how could the Model exist prior to the action being called? You don't know what Model is going to be created until after it's happened.

这篇关于里面ActionFilter型号的可用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆