The controller knows the action that is being invoked and by convention if you don't specify a view name it will look in Views/ControllerName/ActionName.aspx
(.ascx
) for a corresponding view. If it doesn't find it will show you a list of searched locations.
Here are more details about how it works:
- A request comes in
/ControllerName/ActionName
- The request is intercepted by the ASP.NET pipeline and the routing engine based on the configuration extracts the tokens. If default routes are configured it extracts controller="ControllerName" and action="ActionName".
- The routing engine looks in the controller cache to see if a type corresponding to the name
ControllerNameController
exists.
- If it does exist it is instantiated using a controller factory and the method called ActionName is invoked. If the controller doesn't exist and the default controller factory is used reflection is used to find all types deriving from
Controller
in all referenced assemblies and those types are cached.
- The action is executed and the view engine will look for a template stored using the conventions described previously.