| This post is a digest of the Understanding Models, Views, and Controllers (C#). It helps to quickly understand the generated code when creating ASP.NET MVC project in Visual Studio.
ASP.NET MVC Project in Visual Studio
- Three folders created: Models, Views (ASPX pages sit here), Controllers
- Urls are SEO friendly (/Home/About)
- No direct correspondence between URL and the page.
Requests mapped to Controller's actions
ASP.NET Web Forms are content centric
ASP.NET MVC is logic centric
ASP.NET Routing maps request to action.
Routing is registered in Global.asax
- Controls user interaction (flow) with ASP.NET MVC application.
- Derive from Controller class.
- Exposes actions that can return ActionResult.
- Any public method is action (WARNING: can be invoked freely via URL).
- A controller should only contain the bare minimum of logic required to return the right view or redirect the user to another action (flow control).
- Create folders by Controllers names.
- Create sub-folders to reflect views that Controller handles.
- View is ASPX page that inherits from System.Web.Mvc.ViewPage
- View should contain only logic related to generating the user interface.
- An MVC model contains all of your application logic that is not contained in a view or a controller.
This post is made with PracticeThis.com plugin for Windows Live Writer