MVC Life Cycle – 5th Part

Hi Friends,

In this section, we will look at Action Execution event in the MVC life Cycle. Once, controller gets initialized then action invoker has to take decision saying which method to invoke and this piece is done by Action Invoker in the life cycle. Action Invoker based on different method signatures present in controller identifies the exact method to be invoked.

In the above snippet, there are two about methods. In this case, it has become ambiguous for action invoker to figureout to choose which method to pick and hence produced below error. 19th   However, this can be easily fixed by applying any HTTP Verbs or Action Selectors like shown below.  


However, there could be a scenario where in multiple GET request is required and action should be taken on certain additional conditions, be it any thing. In that case, we need to make use custom action invoker wherein it will check whether the requested method is valid or not and then based on that, it will take decision as shown below.

I have also modified the controller code to check whether request is valid or not.

With the above change in place, when I run the program and click the about link, it will first check the attribute code and then accordingly take decision as shown below.




And if I make the action invoker method check to return true like shown below, then it will produce the JSON Result.



I hope you would have liked the discussion of MVC Action Invoker and how important it is to make the decision making process while selecting the required method inside the controller. In the coming section, We will see more around this.Till then stay tuned and Happy Coding.

Code Download Link:-

Rahul Sahay
Happy Coding

Thanks, Rahul Happy Coding