When I created my first MVC project I noticed this method named Index which is created automatically by MVC framework.
When you move mouse over the View() method you will see it returns a instance of ViewResult type but not a ActionResult type. The ViewResult type is actually inherited indirectly from ActionResult type. The complete inheritance structure is:
The whole story here is we created a Index action for current Controller which means when you just go to this website and don’t specify any page name you will go into this Index action. What this action does is initialize the page view and return a ViewResult object for MVC viewer to use.
public ActionResult Index()
{
// Add action logic here
return View();
}
{
// Add action logic here
return View();
}
When you move mouse over the View() method you will see it returns a instance of ViewResult type but not a ActionResult type. The ViewResult type is actually inherited indirectly from ActionResult type. The complete inheritance structure is:
ActionResult
|
|--PartialViewResult
|
|----ViewResult
|
|--PartialViewResult
|
|----ViewResult
The whole story here is we created a Index action for current Controller which means when you just go to this website and don’t specify any page name you will go into this Index action. What this action does is initialize the page view and return a ViewResult object for MVC viewer to use.
No comments:
Post a Comment