开发者

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 met开发者_C百科hod is executed. Kind of like a viewstate mechanism.

J.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜