This document provides an introduction to ASP.NET MVC, including a comparison to ASP.NET Web Forms. It outlines some problems with the Web Forms approach like tight coupling and difficulty with unit testing. MVC is introduced as an architectural pattern that enforces separation of concerns into models, views, and controllers. The request flow for ASP.NET MVC is described as starting with a request hitting a controller, which calls a model and identifies a view to render the model data and send a response. Examples of an MVC model, view, and controller are also provided.
2. Agenda
• Asp.Net Webforms?
• Web-Forms : Request Flow
• Problems with Web-Forms Approach
• Why does Microsoft need MVC?
• What is MVC?
• Asp.Net MVC Request Flow
• Example
3. Asp.net Web Forms?
• Visual Programming Approach
– Drag & Drop controls
• Rich Controls
– Dropdownlist, GridView, TreeView etc.
• RAD : Rapid Application Development
• Event Driven Development (Web)
4. Example : Web-Forms
UI (Login.aspx) & its design view (below) Code Behind (Login.aspx.cs)
5. Request Flow
• Request comes with Http
Get / Post for a page
(aspx)
• Aspx page invokes Page
life cycle events, then
invokes appropriate
action
• Sent the result in HTML
format to request
browser (end-users)
6. Problems with Web-Forms
• Project Architecture
– No Fixed Architecture
– One may use 3 Layer Architecture
– One may write everything in code-behind file
• Unit Testing or TDD is difficult
– Difficult to mock Sender & EventArgs
• View State
– Stores on client side so reduces performance
• Tight Coupling
– Reusability is not there as we can’t use same code behind
7. Why Does Microsoft Need MVC?
• Enforces Separation of Concerns
– Model
– View
– Controller
• Test Driven Development
– Controllers are not bound to any view. Can be mock easily
• No View State
• No server side controls
– Developers have full control on rendered HTML.
8. What is MVC?
• An Architectural Pattern
• Model
– It is a plan / template of an entity.
– It contains validation logic, business logic, database access logic etc.
• View
– It is simple html markup(User Interface)
– It can be associated with Model.
– View display data using Model to the user.
• Controller
– It handles http request.
– It contacted with Model & fills the model object with data.
– Then it finds out the appropriate view & render it with model object
data.
9. Asp.Net MVC Request Flow
1
Controller
Model
View
2
3
4
5
• Request Comes & hits the
controller
• Controller calls model to do
some business
• Model returns the result of
operation to controller
• Controller identifies which
view needs to be rendered
with the data comes from
model
• In the final step view renders
the data & send response to
client