SlideShare a Scribd company logo
2
Most read
3
Most read
7
Most read
Introducing ASP .NET MVC
Points for discussion
•Introduction to Asp.NET MVC
•Architecture of Asp.NET MVC
•Model
•View
•Controller
•Goals of ASP.NET MVC
•File Structure
•Page Life Cycle
•Global.asax
Introducing ASP .NET MVC
• ASP .NET Web Controls have many benefits
    • They allow web applications to be built rapidly
    • They provide a very rich user experience
    • They can easily be bound to data sources
• But there are many disadvantages
    • As functionality increases so does the number of post-
    backs
    • The amount of View State data can grow alarmingly
    • The underlying HTTP infrastructure is not hidden
• The most serious problems are architectural
    • ASP .NET actively discourages MVC based best practices.
Architecture of ASP .NET MVC
What is a Model?
•MVC model is basically a C# or VB.NET class
•A model is accessible by both controller and view
•A model can be used to pass data from Controller to
view
•A view can use model to display data in page
What is a View?
•View is an ASPX page without having a code behind
file
•All page specific HTML generation and formatting can
be done inside view
•One can use Inline code (server tags ) to develop
dynamic pages
•A request to view (ASPX page) can be made only from
a controller’s action method
What is a Controller?
•Controller is basically a C# or VB.NET class which
inherits System.Mvc.Controller
•Controller is a heart of the entire MVC architecture
•Inside Controller’s class action methods can be
implemented which are responsible for responding to
browser OR calling views.
•Controller can access and use Model class to pass data
to Views
•Controller uses ViewData to pass any data to View
Goals of ASP .NET MVC
•Enable proper unit and integration tests
   • Controllers can be tested without the browser
   • Data access layer can be ‘mocked out’
• Transparent   naming conventions
   • URL’s are simple and clean
•Take control over markup
•Build on top of ASP .NET infrastructure
   • But make the post-back style controls optional
MVC File Structure & File Naming Standards

•MVC uses a standard directory structure and file naming standards
which are a very important part of MVC application development.
•Inside the ROOT directory of the application, there must be 3
directories each for model, view and Controller.
•Apart from 3 directories, there must have a Global.asax file in root
folder, and a web.config like a traditional ASP.NET application.
ASP.NET MVC Execution Life Cycle
Page Life Cycle
• The ‘UrlRoutingModule’ receives the request
   •It creates and runs the correct ‘MvcHandler’
•The handler creates and runs a controller
   •Creation is via the current ‘ControllerFactory’
   •The entry point to the controller is ‘Execute’
        •A ‘ControllerContext’ is passed as a parameter
•The controller runs the appropriate method
   •This is found using standard reflection
   •A list of parameters can be passed in
•Control is passed to the current ‘ViewEngine’
   • Which (typically) builds and calls a server page
Global.asax
public class MvcApplication : System.Web.HttpApplication {
   public static void RegisterRoutes(RouteCollection routes) {
          routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
          routes.MapRoute(
              "Default", // Route name
              "{controller}/{action}/{id}", // URL with parameters
              new { controller = "Home", action = "Index", id = "" }
          );
   }

     protected void Application_Start() {
         RegisterRoutes(RouteTable.Routes);
    }
}
Passing Data Into The Server Page
•   The simplest mechanism for passing data to the server
    page is via the ‘ViewData’ object
    •This is a dictionary that holds arbitrary objects
    •The dictionary is populated in the controller and
    automatically passed to the server page by the
    ‘MvcHandler’
•Information can be retrieved via a key or via generics
    •E.g. ‘ViewData[“order”]’ or ViewData.Get<Order>()
•A more strongly typed solution is possible
    •An arbitrary object is passed back from the controller
    •The server page inherits from ‘ViewPage<T>’
        •Where ‘T’ is set to the type returned from the
        controller
Mixing MVC with Normal ASP .NET
•There is no problem combining MVC and Web Forms
    •As everything is based on the same infrastructure
• An ASP .NET Web Application can contain:
    •MVC based controllers, actions and views
    •ASP .NET pages containing HTML and Web Controls
    •Windows Communication Foundation based Web
    Services
• Some changes may be required to routing tables
    • MVC can be configured to ignore requests to existing
    files
    •But you may wish to add explicit exceptions to prevent
    unnecessary calls which access the file system
•You can do this via ‘routes.IgnoreRoute(“...”)’
Using AJAX in Web Applications
•MVC uses jQuery to implement AJAX
   •Using ‘Ajax.BeginForm()’ you can generate markup and
   scripts that support partial post-backs
        •It takes an ‘AjaxOptions’ parameter that holds the
        ids of elements to be updated and where updates
        should be placed
   •This can be detected via ‘Request.IsMvcAjaxRequest’
        •You then send changes via ‘return PartialView(...)’
•ASP .NET AJAX is not replaced
   •It remains a better option for:
        •Calling .NET based Web Services
        •Creating client-side only controls
   •Plus there is all the code in the control toolkit
Conclusion
• Uses MVC design pattern for separation of different
parts of the application
•More scalable
•More and easily extensible
•More testable for business logic.
•Supports EF like LINQ to SQL,ADO.NET EF Model,
Standard ADO.NET for readers and Datasets etc

More Related Content

PPTX
Introduction to Spring Framework
PDF
Hibernate Presentation
PDF
Java Collection framework
PDF
Spring MVC Framework
PDF
Asp.net mvc basic introduction
PPTX
ASP.NET MVC Presentation
PPTX
Introduction to ASP.NET Core MVC and the MVC Pattern.pptx
PDF
Spring MVC
Introduction to Spring Framework
Hibernate Presentation
Java Collection framework
Spring MVC Framework
Asp.net mvc basic introduction
ASP.NET MVC Presentation
Introduction to ASP.NET Core MVC and the MVC Pattern.pptx
Spring MVC

What's hot (20)

PPT
Types of exceptions
PPT
C#.NET
PDF
Java Course 11: Design Patterns
PPTX
Introduction to mvc architecture
PPTX
React js programming concept
PPT
Developing Java Web Applications
PDF
JavaScript - Chapter 4 - Types and Statements
PPTX
Sequence diagram
PPT
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
PDF
GraphQL Data Loaders - How to feed your GraphQL API with data the smart way
PPTX
Introduction to ASP.NET
PDF
ES6 presentation
PPTX
Asp.net and .Net Framework ppt presentation
PPT
Data Flow Diagram
PPT
Java Persistence API (JPA) Step By Step
PDF
C# Delegates and Event Handling
PPTX
JS Event Loop
PPTX
React-JS.pptx
PPT
Adapter pattern
Types of exceptions
C#.NET
Java Course 11: Design Patterns
Introduction to mvc architecture
React js programming concept
Developing Java Web Applications
JavaScript - Chapter 4 - Types and Statements
Sequence diagram
Basic Concepts of OOPs (Object Oriented Programming in Java)
GraphQL Data Loaders - How to feed your GraphQL API with data the smart way
Introduction to ASP.NET
ES6 presentation
Asp.net and .Net Framework ppt presentation
Data Flow Diagram
Java Persistence API (JPA) Step By Step
C# Delegates and Event Handling
JS Event Loop
React-JS.pptx
Adapter pattern
Ad

Similar to Introduction to ASP.Net MVC (20)

PPTX
Hanselman lipton asp_connections_ams304_mvc
PPTX
Asp.Net Mvc
PPS
Introduction To Mvc
PDF
ASP.NET MVC 2.0
PPT
Asp.net,mvc
PPTX
Aspnet mvc
PPTX
Asp.net With mvc handson
PPTX
ASP.NET Presentation
PPTX
Asp.Net MVC3 - Basics
PDF
Aspnetmvc 1
PDF
Asp 1a-aspnetmvc
PPTX
Asp.net mvc presentation by Nitin Sawant
PPTX
Model view controller (mvc)
PDF
ASP.NET MVC - Whats The Big Deal
PPT
CTTDNUG ASP.NET MVC
PPT
ASP .net MVC
PDF
Asp.Net MVC Framework Design Pattern
PPTX
8-9-10. ASP_updated8-9-10. ASP_updated8-9-10. ASP_updated
PPTX
PDF
ASP NET MVC in Action 1st Edition Jeffrey Palermo
Hanselman lipton asp_connections_ams304_mvc
Asp.Net Mvc
Introduction To Mvc
ASP.NET MVC 2.0
Asp.net,mvc
Aspnet mvc
Asp.net With mvc handson
ASP.NET Presentation
Asp.Net MVC3 - Basics
Aspnetmvc 1
Asp 1a-aspnetmvc
Asp.net mvc presentation by Nitin Sawant
Model view controller (mvc)
ASP.NET MVC - Whats The Big Deal
CTTDNUG ASP.NET MVC
ASP .net MVC
Asp.Net MVC Framework Design Pattern
8-9-10. ASP_updated8-9-10. ASP_updated8-9-10. ASP_updated
ASP NET MVC in Action 1st Edition Jeffrey Palermo
Ad

Recently uploaded (20)

PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Encapsulation theory and applications.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Modernizing your data center with Dell and AMD
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
cuic standard and advanced reporting.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Encapsulation theory and applications.pdf
Network Security Unit 5.pdf for BCA BBA.
Encapsulation_ Review paper, used for researhc scholars
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The AUB Centre for AI in Media Proposal.docx
Building Integrated photovoltaic BIPV_UPV.pdf
NewMind AI Monthly Chronicles - July 2025
Per capita expenditure prediction using model stacking based on satellite ima...
Modernizing your data center with Dell and AMD
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Dropbox Q2 2025 Financial Results & Investor Presentation
NewMind AI Weekly Chronicles - August'25 Week I
Unlocking AI with Model Context Protocol (MCP)
cuic standard and advanced reporting.pdf
Electronic commerce courselecture one. Pdf
Empathic Computing: Creating Shared Understanding
Chapter 3 Spatial Domain Image Processing.pdf

Introduction to ASP.Net MVC

  • 2. Points for discussion •Introduction to Asp.NET MVC •Architecture of Asp.NET MVC •Model •View •Controller •Goals of ASP.NET MVC •File Structure •Page Life Cycle •Global.asax
  • 3. Introducing ASP .NET MVC • ASP .NET Web Controls have many benefits • They allow web applications to be built rapidly • They provide a very rich user experience • They can easily be bound to data sources • But there are many disadvantages • As functionality increases so does the number of post- backs • The amount of View State data can grow alarmingly • The underlying HTTP infrastructure is not hidden • The most serious problems are architectural • ASP .NET actively discourages MVC based best practices.
  • 5. What is a Model? •MVC model is basically a C# or VB.NET class •A model is accessible by both controller and view •A model can be used to pass data from Controller to view •A view can use model to display data in page
  • 6. What is a View? •View is an ASPX page without having a code behind file •All page specific HTML generation and formatting can be done inside view •One can use Inline code (server tags ) to develop dynamic pages •A request to view (ASPX page) can be made only from a controller’s action method
  • 7. What is a Controller? •Controller is basically a C# or VB.NET class which inherits System.Mvc.Controller •Controller is a heart of the entire MVC architecture •Inside Controller’s class action methods can be implemented which are responsible for responding to browser OR calling views. •Controller can access and use Model class to pass data to Views •Controller uses ViewData to pass any data to View
  • 8. Goals of ASP .NET MVC •Enable proper unit and integration tests • Controllers can be tested without the browser • Data access layer can be ‘mocked out’ • Transparent naming conventions • URL’s are simple and clean •Take control over markup •Build on top of ASP .NET infrastructure • But make the post-back style controls optional
  • 9. MVC File Structure & File Naming Standards •MVC uses a standard directory structure and file naming standards which are a very important part of MVC application development. •Inside the ROOT directory of the application, there must be 3 directories each for model, view and Controller. •Apart from 3 directories, there must have a Global.asax file in root folder, and a web.config like a traditional ASP.NET application.
  • 10. ASP.NET MVC Execution Life Cycle
  • 11. Page Life Cycle • The ‘UrlRoutingModule’ receives the request •It creates and runs the correct ‘MvcHandler’ •The handler creates and runs a controller •Creation is via the current ‘ControllerFactory’ •The entry point to the controller is ‘Execute’ •A ‘ControllerContext’ is passed as a parameter •The controller runs the appropriate method •This is found using standard reflection •A list of parameters can be passed in •Control is passed to the current ‘ViewEngine’ • Which (typically) builds and calls a server page
  • 12. Global.asax public class MvcApplication : System.Web.HttpApplication { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } ); } protected void Application_Start() { RegisterRoutes(RouteTable.Routes); } }
  • 13. Passing Data Into The Server Page • The simplest mechanism for passing data to the server page is via the ‘ViewData’ object •This is a dictionary that holds arbitrary objects •The dictionary is populated in the controller and automatically passed to the server page by the ‘MvcHandler’ •Information can be retrieved via a key or via generics •E.g. ‘ViewData[“order”]’ or ViewData.Get<Order>() •A more strongly typed solution is possible •An arbitrary object is passed back from the controller •The server page inherits from ‘ViewPage<T>’ •Where ‘T’ is set to the type returned from the controller
  • 14. Mixing MVC with Normal ASP .NET •There is no problem combining MVC and Web Forms •As everything is based on the same infrastructure • An ASP .NET Web Application can contain: •MVC based controllers, actions and views •ASP .NET pages containing HTML and Web Controls •Windows Communication Foundation based Web Services • Some changes may be required to routing tables • MVC can be configured to ignore requests to existing files •But you may wish to add explicit exceptions to prevent unnecessary calls which access the file system •You can do this via ‘routes.IgnoreRoute(“...”)’
  • 15. Using AJAX in Web Applications •MVC uses jQuery to implement AJAX •Using ‘Ajax.BeginForm()’ you can generate markup and scripts that support partial post-backs •It takes an ‘AjaxOptions’ parameter that holds the ids of elements to be updated and where updates should be placed •This can be detected via ‘Request.IsMvcAjaxRequest’ •You then send changes via ‘return PartialView(...)’ •ASP .NET AJAX is not replaced •It remains a better option for: •Calling .NET based Web Services •Creating client-side only controls •Plus there is all the code in the control toolkit
  • 16. Conclusion • Uses MVC design pattern for separation of different parts of the application •More scalable •More and easily extensible •More testable for business logic. •Supports EF like LINQ to SQL,ADO.NET EF Model, Standard ADO.NET for readers and Datasets etc