Mark
Mark

Reputation: 404

MVC ActionMethod Controller events?

Is there an event that is fired prior to an action method being called in a controller? I have some common 'page control' specific variables that are passed from client to server in nearly all acton methods and would benefit from a hanlder that would allow me to retrieve these values and map them to my own data structures before the action method is executed. Kind of like a viewstate mechanism.

J.

Upvotes: 0

Views: 4663

Answers (2)

nathan gonzalez
nathan gonzalez

Reputation: 11987

based on the last part of your question

allow me to retrieve these values and map them to my own data structures before the action method is executed

i think you're probably going to be best served by looking into custom model binding. that way you can pull the data into a strongly typed parameter that looks how you want it to, but only so long as that parameter is present.

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

Is there an event that is fired prior to an action method being called in a controller?

You could override the OnActionExecuting method. Another more reusable solution is to write a custom action filter and then decorate your controllers/actions with it or even declare it as a global action filter so that it applies to all the controllers and actions in the application.

Upvotes: 4

Related Questions