SlideShare a Scribd company logo
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

What's hot

Flux architecture
Flux architectureFlux architecture
Flux architecture
Boyan Mihaylov
 
Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAs
Jennifer Estrada
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin Lau
Spiffy
 
ASP.NET 4.0 Roadmap
ASP.NET 4.0 RoadmapASP.NET 4.0 Roadmap
ASP.NET 4.0 Roadmap
Harish Ranganathan
 
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web AppsSession 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
PawanMM
 
Ch 04 asp.net application
Ch 04 asp.net application Ch 04 asp.net application
Ch 04 asp.net application
Madhuri Kavade
 
ASP .NET MVC - best practices
ASP .NET MVC - best practicesASP .NET MVC - best practices
ASP .NET MVC - best practices
Bohdan Pashkovskyi
 
Sitecore MVC: What it is and why it's important
Sitecore MVC: What it is and why it's importantSitecore MVC: What it is and why it's important
Sitecore MVC: What it is and why it's important
nonlinear creations
 
Web api
Web apiWeb api
ASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline InternalsASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline Internals
Lukasz Lysik
 
Dot net interview questions and asnwers
Dot net interview questions and asnwersDot net interview questions and asnwers
Dot net interview questions and asnwers
kavinilavuG
 
ASP.NET Lecture 2
ASP.NET Lecture 2ASP.NET Lecture 2
ASP.NET Lecture 2
Julie Iskander
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
priya Nithya
 
ASP.NET lecture 8
ASP.NET lecture 8ASP.NET lecture 8
ASP.NET lecture 8
Julie Iskander
 
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
SPTechCon
 
Esri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc FinalEsri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc Final
guestcd4688
 
Simple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnanSimple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnan
Gigin Krishnan
 
Advanced SharePoint Web Part Development
Advanced SharePoint Web Part DevelopmentAdvanced SharePoint Web Part Development
Advanced SharePoint Web Part Development
Rob Windsor
 
Web controls
Web controlsWeb controls
Web controls
Sarthak Varshney
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
Jennifer Estrada
 

What's hot (20)

Flux architecture
Flux architectureFlux architecture
Flux architecture
 
Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAs
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin Lau
 
ASP.NET 4.0 Roadmap
ASP.NET 4.0 RoadmapASP.NET 4.0 Roadmap
ASP.NET 4.0 Roadmap
 
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web AppsSession 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
 
Ch 04 asp.net application
Ch 04 asp.net application Ch 04 asp.net application
Ch 04 asp.net application
 
ASP .NET MVC - best practices
ASP .NET MVC - best practicesASP .NET MVC - best practices
ASP .NET MVC - best practices
 
Sitecore MVC: What it is and why it's important
Sitecore MVC: What it is and why it's importantSitecore MVC: What it is and why it's important
Sitecore MVC: What it is and why it's important
 
Web api
Web apiWeb api
Web api
 
ASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline InternalsASP.NET MVC 4 Request Pipeline Internals
ASP.NET MVC 4 Request Pipeline Internals
 
Dot net interview questions and asnwers
Dot net interview questions and asnwersDot net interview questions and asnwers
Dot net interview questions and asnwers
 
ASP.NET Lecture 2
ASP.NET Lecture 2ASP.NET Lecture 2
ASP.NET Lecture 2
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
 
ASP.NET lecture 8
ASP.NET lecture 8ASP.NET lecture 8
ASP.NET lecture 8
 
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
 
Esri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc FinalEsri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc Final
 
Simple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnanSimple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnan
 
Advanced SharePoint Web Part Development
Advanced SharePoint Web Part DevelopmentAdvanced SharePoint Web Part Development
Advanced SharePoint Web Part Development
 
Web controls
Web controlsWeb controls
Web controls
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 

Similar to Introduction to ASP.Net MVC

Using MVC with Kentico 8
Using MVC with Kentico 8Using MVC with Kentico 8
Using MVC with Kentico 8
Thomas Robbins
 
Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013
Thomas Robbins
 
ASP.NET MVC 2.0
ASP.NET MVC 2.0ASP.NET MVC 2.0
ASP.NET MVC 2.0
Buu Nguyen
 
Asp 1-mvc introduction
Asp 1-mvc introductionAsp 1-mvc introduction
Asp 1-mvc introduction
Fajar Baskoro
 
ASP.NET - Building Web Application..in the right way!
ASP.NET - Building Web Application..in the right way!ASP.NET - Building Web Application..in the right way!
ASP.NET - Building Web Application..in the right way!
Commit Software Sh.p.k.
 
Aspnetmvc 1
Aspnetmvc 1Aspnetmvc 1
Aspnetmvc 1
Fajar Baskoro
 
Asp.net With mvc handson
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handson
Prashant Kumar
 
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
Ashton Feller
 
MVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming modelMVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming model
Alex Thissen
 
2011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 52011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 5
Daniel Fisher
 
Mvc
MvcMvc
Introduction to ASP.NET MVC
Introduction to ASP.NET MVC Introduction to ASP.NET MVC
Introduction to ASP.NET MVC
Joe Wilson
 
Asp.net mvc basic introduction
Asp.net mvc basic introductionAsp.net mvc basic introduction
Asp.net mvc basic introduction
Bhagath Gopinath
 
Mvc fundamental
Mvc fundamentalMvc fundamental
Mvc fundamental
Nguyễn Thành Phát
 
4. Introduction to ASP.NET MVC - Part I
4. Introduction to ASP.NET MVC - Part I4. Introduction to ASP.NET MVC - Part I
4. Introduction to ASP.NET MVC - Part I
Rohit Rao
 
Asp.net mvc presentation by Nitin Sawant
Asp.net mvc presentation by Nitin SawantAsp.net mvc presentation by Nitin Sawant
Asp.net mvc presentation by Nitin Sawant
Nitin Sawant
 
Asp.net,mvc
Asp.net,mvcAsp.net,mvc
Asp.net,mvc
Prashant Kumar
 
Aspnet mvc
Aspnet mvcAspnet mvc
Aspnet mvc
Hiep Luong
 
MVC architecture
MVC architectureMVC architecture
Mvc Brief Overview
Mvc Brief OverviewMvc Brief Overview
Mvc Brief Overview
rainynovember12
 

Similar to Introduction to ASP.Net MVC (20)

Using MVC with Kentico 8
Using MVC with Kentico 8Using MVC with Kentico 8
Using MVC with Kentico 8
 
Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013
 
ASP.NET MVC 2.0
ASP.NET MVC 2.0ASP.NET MVC 2.0
ASP.NET MVC 2.0
 
Asp 1-mvc introduction
Asp 1-mvc introductionAsp 1-mvc introduction
Asp 1-mvc introduction
 
ASP.NET - Building Web Application..in the right way!
ASP.NET - Building Web Application..in the right way!ASP.NET - Building Web Application..in the right way!
ASP.NET - Building Web Application..in the right way!
 
Aspnetmvc 1
Aspnetmvc 1Aspnetmvc 1
Aspnetmvc 1
 
Asp.net With mvc handson
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handson
 
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
 
MVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming modelMVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming model
 
2011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 52011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 5
 
Mvc
MvcMvc
Mvc
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVC Introduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
Asp.net mvc basic introduction
Asp.net mvc basic introductionAsp.net mvc basic introduction
Asp.net mvc basic introduction
 
Mvc fundamental
Mvc fundamentalMvc fundamental
Mvc fundamental
 
4. Introduction to ASP.NET MVC - Part I
4. Introduction to ASP.NET MVC - Part I4. Introduction to ASP.NET MVC - Part I
4. Introduction to ASP.NET MVC - Part I
 
Asp.net mvc presentation by Nitin Sawant
Asp.net mvc presentation by Nitin SawantAsp.net mvc presentation by Nitin Sawant
Asp.net mvc presentation by Nitin Sawant
 
Asp.net,mvc
Asp.net,mvcAsp.net,mvc
Asp.net,mvc
 
Aspnet mvc
Aspnet mvcAspnet mvc
Aspnet mvc
 
MVC architecture
MVC architectureMVC architecture
MVC architecture
 
Mvc Brief Overview
Mvc Brief OverviewMvc Brief Overview
Mvc Brief Overview
 

Recently uploaded

Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
BibashShahi
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
Edge AI and Vision Alliance
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 

Recently uploaded (20)

Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 

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