Question

I have read the following article about MVC page life cycle:

http://blogs.msdn.com/b/varunm/archive/2013/10/03/understanding-of-mvc-page-life-cycle.aspx?CommentPosted=true#commentmessage

But in the first stanza of the fifth point it's mention that (quote):

"The Controller typically either executes either the RedirectToAction Method or the RenderView Method. When you call a controller’s RenderView() method,the call is delegated to the current ViewEngine’s RenderView() method."

(See the text in bold above.) On looking into the controller class, I found the there is no RenderView method there.

So I am unable find the missing link where the code delegate the call to ViewEngines RenderView method, as there is no RenderView (method, delegate, virtual method, abstract method) in Controller class.

An explanation would be highly appreciated. Thanks in advance.

Was it helpful?

Solution

The Controller is not responsible for calling RenderView method. It's the ControllerActionInvoker that executes the controller action and invokes the ExecuteResult method on the returned ActionResult from the controller action. All this happens inside the ExecuteCore method of the Controller.

Then depending on the actual ActionResult class different things will happen. If you returned a ViewResult or a PartialViewResult, the ExecuteResult method will delegate the actual execution to the view engine. And finally the view engine will invoke the RenderView method.

From inside a controller you cannot and should not be rendering views. That's not the responsibility of a controller in MVC.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top