Model availability inside ActionFilter
Asked Answered
G

2

0

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.

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.

Gybe answered 15/3, 2010 at 3:39 Comment(0)
S
0

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.

Spirograph answered 15/3, 2010 at 3:49 Comment(2)
Thanks, I was looking to modify the model created by the binder. I will find another way.Gybe
The controller action does not create it if the method is POSTGav
M
1

Sayed, you usually set a model during the execution of an action. Therefore, it is natural that the model is null during the execution of the OnActionExecuting which occurs before the action is called.

Murrah answered 15/3, 2010 at 3:50 Comment(0)
S
0

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.

Spirograph answered 15/3, 2010 at 3:49 Comment(2)
Thanks, I was looking to modify the model created by the binder. I will find another way.Gybe
The controller action does not create it if the method is POSTGav

© 2022 - 2024 — McMap. All rights reserved.