Introduction to ASP.NET MVC
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
Asp.net Web Forms?
• Visual Programming Approach
– Drag & Drop controls
• Rich Controls
– Dropdownlist, GridView, TreeView etc.
• RAD : Rapid Application Development
• Event Driven Development (Web)
Example : Web-Forms
UI (Login.aspx) & its design view (below) Code Behind (Login.aspx.cs)
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)
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
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.
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.
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
Example : Model
Example : View
Example : Controller
Example : Output

4. Introduction to ASP.NET MVC - Part I

  • 1.
  • 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 • Requestcomes 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 MicrosoftNeed 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 RequestFlow 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
  • 10.
  • 11.
  • 12.
  • 13.