Introduction to ASP.NET MVC

WebForms history:
* ASP.NET created to replaced classic ASP
* Abstract away the Web part.
* Click Events replaced post operations
* 90’s =>
* Web Standards have strengthened
* Client-side programming has increased.
* WebForms competidors have implemented MVC
+ Struts (Java)
+ Ruby on Rails (RoR)
+ Django (Python)

ASP.Net MVC Design Goals:
* It’s an alternative project type.
* It’s compatible with ASP.NET (runs on ASP.NET)
* Embrace the web: no page lifecycle, you have to write your own Clean
HTML and URLs
* Extensible: it’s able to inject our own logic
* Testable: we can test controllers, views, by separate.

MVC - The pattern
Controller
Model  <=  View

It’s not new, it has been there for decades
View: Rendering user interfase (HTML), does not have logic inside, talk
to the model
Model: has all the data the view display
Controller: when an http request arrives talks to the controller, that
build a model, select the view to render the model to the user
All the hard work is inside the controller.
Build the model (Does not handle state)
Select the View (does not interact to the user interfase)

Web Forms:
Get Http Request => .ASPX (Page) => Http Response
the logic is inside the file (Page)
ASP.NET MVC
Get HTTP Request => Controller => .ASP (View) => HTTP Response
The request is routed to a controller, the controller pick a view

MVC Routing:
* System.Web.Routing: it’s used also for Webforms.
The routes are defined in the Global.ASAX
The routes engine will pick the first one that maches.
"{controller}/{action}/{id}"

ActionResult => ViewResult, JSonResult, etc

MVC is convention oriented, if names are fine, everything should run
just fine.
You don’t use Grids or things like that in MVC because violates the idea
of avoid page lifecycle, etc.