SlideShare a Scribd company logo
1 of 27
Introduction To ASP.NET MVC 4
Nitin Sawant
.NET developer
Webforms Pros
• Rich Controls (grids, etc…)
• RAD
• Event Driven (like Winforms)
• Stateful
• Less Control
• No built-in Separation of Concerns (SoC)
• Complicated Page life-cycle
• Not SEO friendly
 URL
 Big Viewstate at the beginning of the page
Webforms Cons
MVC Pattern
• What is MVC?
• Why MVC?
• Who uses MVC?
…“the concept of the design pattern in
software provides a key to helping developers
leverage the expertise of other skilled
architects.”
Grady Booch, 1995
 MVC - Acronym for Model-View-Controller
 MVC is a architectural pattern
 Invented by Trygve Reenskaug in 1978
 Originally used as an architectural pattern for building GUIs.
MVC Pattern
What is it?
Why MVC?
ASP.NET MVC Pros
 More control over your html and JavaScript
 Separation of Concerns (SoC)
 SEO friendly
 Test Driven Development (TDD)
 Highly flexible & customizable
 Not RAD
 No rich controls
ASP.NET MVC Cons
MVC Pattern
Who uses it?
• .NET has Spring.NET and MonoRail
• Java has Swing, Struts, Grails and others
• Perl has Catalyst, Gantry, Jifty and others
• PHP has Zend, Zoop, Agavi and others
• Python has Django, Gluon, Pylon and others
• Ruby has Ruby on Rails
• Apple has cocoa and cocoa touch for objective-c [Mac, iPhone]
ASP.Net MVC Overview
• ASP.NET MVC?
• ASP.Net MVC Execution Process
• ASP.Net MVC 4 Project Structure
ASP.Net MVC Overview
ASP.Net MVC Architecture
M
Model
V
View
C
Controller
• Representation of domain data
• Business Logic
• Persistence mechanisms
• User Interface
• The representation of Model
• An intermediary between Model and View
• Application’s Brain (Handle user requests, bind
Data, return views)
ASP.NET
Dynamic Data
ASP.NET
WebForms
ASP.NET
MVC
Presentation
Runtime
ASP.NET
Core
It’s not a replacement for asp.net webforms, it’s a new flavour of asp.net
ASP.Net MVC Overview
ASP.Net MVC?
ASP.Net MVC Overview
ASP.Net MVC Execution Process
ASP.NET MVC 4 Project
Structure
1. App_Data folder is the physical store for data.
2. Content folder keeps files such as scripts, CSS, images, etc
3. Controllers folder is the location for controllers.
4. Models stores classes that handle application domain logic.
5. Scripts folder is for script files. By default, this folder
contains AJAX script files and the JQuery library.
6. Views is the recommended location for views. View files
use .cshtml extension.
Routing R => the hidden characterMVC +R
1. Maps incoming URLs to the application and routes them to the right
Controller’s Action method to execute them
2. Happens in RegisterRoutes function in the global.asax file
Routing
Don’t settle for…
/ProductsDetails.aspx?CategoryID=123
When you can easily have…
/Product/Details/123/
Or whatever else makes sense…
Routing
To customize routing rules
Model [M]
Model
• It’s the core of your application
• A place for business logic, data access, Validation ... etc
• You can use your favorite data access technology with
ASP.NET MVC [LINQ to SQL, Nhibernate, Entity Framework
…etc]
Controller [C]
Controls the flow of application execution
 Controller is a class containing a set of action methods.
 Responsible for
o Handling user interaction
o Working with the models
o Selecting a view to render
o Sending model and information to a particular view
o Making decisions for security, UI, redirects ... etc.
 The ASP.Net MVC requires the names of all controllers to end with the
suffix "Controller“ e.g. HomeController, LoginController & ProductController
Controller
Actions Rules:
1) Must be a public method
2) Cannot be a static method
3) Cannot be an extension method
4) Cannot be a constructor or property
5) Cannot have generic type.
6) Cannot contain ref or out parameters.
Controller
Controller Actions
An action is a method on a controller that gets called when you enter a
particular URL in your browser address bar.
Each action returns ActionResult which can be
• ViewResult => HTML and markup.
• EmptyResult => no result.
• RedirectResult => redirection to a new URL.
• JsonResult => json result that can be used in an AJAX application.
• JavaScriptResult => JavaScript script.
• ContentResult => text result [and wraps any non ActionResult return Type].
• FileContentResult => downloadable file [with the binary content].
• FilePathResult => downloadable file [with a path].
• FileStreamResult => a downloadable file [with a file stream].
A controller action always returns an ActionResult
Controller
Controller Actions
Note: all public methods of a controller class considered as action methods, if
you don’t want a public method to be an action, mark it with [NonAction()]
attribute
View [V]
View
• Responsible for presentation, look & feel, formatting, sorting … etc.
• Interacts with model but doesn’t make any decisions
• No logic should go there
• No View State, No Server Controls
• HTML Helper functions
• Can be strongly typed
• Takes the view data from the controller
Tips:
• @ is equivalent to response.write()
• @{} is used to execute code
• Use @Html.Encode() method to prevent script injection
View Engines
ASPX
Razor
View Engines
ASPX
Razor
• Html.ActionLink()
• Html.BeginForm()
• Html.CheckBox()
• Html.DropDownList()
• Html.EndForm()
• Html.Hidden()
An HTML Helper is just a method that returns a string.
View
HTML Helpers
• Html.ListBox()
• Html.Password()
• Html.RadioButton()
• Html.TextArea()
• Html.TextBox()
e.g.
References
•Official website http://asp.net/mvc
•Source Code http://codeplex.com/aspnet
•Blogs
o Scott Guthrie http://weblogs.asp.net/scottgu
o Rob Conrey http://blog.wekeroad.com
o MVC Store Front http://blog.wekeroad.com/mvc-storefront
o Phil Haack http://haacked.com
o Scott Hanselman http://hanselman.com
o Stephen Walthler http://weblogs.asp.net/stephenwalther
Nitin Sawant
Software Engineer
Email:nitin@nitinsawant.com
T h a n k y o u
www.twitter.com/nitinjs
www.linkedin.com/in/nitinjs

More Related Content

What's hot

Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
Khaled Musaied
 

What's hot (20)

Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
ASP .NET MVC Introduction & Guidelines
ASP .NET MVC Introduction & Guidelines  ASP .NET MVC Introduction & Guidelines
ASP .NET MVC Introduction & Guidelines
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentation
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
MVC 6 Introduction
MVC 6 IntroductionMVC 6 Introduction
MVC 6 Introduction
 
MVC Architecture in ASP.Net By Nyros Developer
MVC Architecture in ASP.Net By Nyros DeveloperMVC Architecture in ASP.Net By Nyros Developer
MVC Architecture in ASP.Net By Nyros Developer
 
Asp.net mvc basic introduction
Asp.net mvc basic introductionAsp.net mvc basic introduction
Asp.net mvc basic introduction
 
Mvc summary
Mvc summaryMvc summary
Mvc summary
 
Asp.net mvc 5 course module 1 overview
Asp.net mvc 5 course   module 1 overviewAsp.net mvc 5 course   module 1 overview
Asp.net mvc 5 course module 1 overview
 
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
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
 
ASP.NET MVC for Begineers
ASP.NET MVC for BegineersASP.NET MVC for Begineers
ASP.NET MVC for Begineers
 
CTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCCTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVC
 
ASP .Net MVC 5
ASP .Net MVC 5ASP .Net MVC 5
ASP .Net MVC 5
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Asp 1a-aspnetmvc
Asp 1a-aspnetmvcAsp 1a-aspnetmvc
Asp 1a-aspnetmvc
 
Mvc
MvcMvc
Mvc
 
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.
 
Dot net interview questions and asnwers
Dot net interview questions and asnwersDot net interview questions and asnwers
Dot net interview questions and asnwers
 

Similar to Asp.net mvc presentation by Nitin Sawant

MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
Dilip Patel
 
Introduction to ASP.Net MVC
Introduction to ASP.Net MVCIntroduction to ASP.Net MVC
Introduction to ASP.Net MVC
Sagar Kamate
 
Hanselman lipton asp_connections_ams304_mvc
Hanselman lipton asp_connections_ams304_mvcHanselman lipton asp_connections_ams304_mvc
Hanselman lipton asp_connections_ams304_mvc
denemedeniz
 

Similar to Asp.net mvc presentation by Nitin Sawant (20)

Asp.net With mvc handson
Asp.net With mvc handsonAsp.net With mvc handson
Asp.net With mvc handson
 
Asp 1-mvc introduction
Asp 1-mvc introductionAsp 1-mvc introduction
Asp 1-mvc introduction
 
Using MVC with Kentico 8
Using MVC with Kentico 8Using MVC with Kentico 8
Using MVC with Kentico 8
 
Aspnetmvc 1
Aspnetmvc 1Aspnetmvc 1
Aspnetmvc 1
 
Mvc
MvcMvc
Mvc
 
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
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
Asp.Net MVC 5 in Arabic
Asp.Net MVC 5 in ArabicAsp.Net MVC 5 in Arabic
Asp.Net MVC 5 in Arabic
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
ASP.NET Presentation
ASP.NET PresentationASP.NET Presentation
ASP.NET Presentation
 
CG_CS25010_Lecture
CG_CS25010_LectureCG_CS25010_Lecture
CG_CS25010_Lecture
 
MVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on RailsMVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on Rails
 
Introduction to ASP.Net MVC
Introduction to ASP.Net MVCIntroduction to ASP.Net MVC
Introduction to ASP.Net MVC
 
Intro to .NET for Government Developers
Intro to .NET for Government DevelopersIntro to .NET for Government Developers
Intro to .NET for Government Developers
 
Session 1
Session 1Session 1
Session 1
 
ASP.NET MVC Best Practices malisa ncube
ASP.NET MVC Best Practices   malisa ncubeASP.NET MVC Best Practices   malisa ncube
ASP.NET MVC Best Practices malisa ncube
 
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
 
Mvc fundamental
Mvc fundamentalMvc fundamental
Mvc fundamental
 
MVC 4
MVC 4MVC 4
MVC 4
 
Hanselman lipton asp_connections_ams304_mvc
Hanselman lipton asp_connections_ams304_mvcHanselman lipton asp_connections_ams304_mvc
Hanselman lipton asp_connections_ams304_mvc
 

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Recently uploaded (20)

%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 

Asp.net mvc presentation by Nitin Sawant

  • 1. Introduction To ASP.NET MVC 4 Nitin Sawant .NET developer
  • 2. Webforms Pros • Rich Controls (grids, etc…) • RAD • Event Driven (like Winforms) • Stateful • Less Control • No built-in Separation of Concerns (SoC) • Complicated Page life-cycle • Not SEO friendly  URL  Big Viewstate at the beginning of the page Webforms Cons
  • 3. MVC Pattern • What is MVC? • Why MVC? • Who uses MVC? …“the concept of the design pattern in software provides a key to helping developers leverage the expertise of other skilled architects.” Grady Booch, 1995
  • 4.  MVC - Acronym for Model-View-Controller  MVC is a architectural pattern  Invented by Trygve Reenskaug in 1978  Originally used as an architectural pattern for building GUIs. MVC Pattern What is it?
  • 5. Why MVC? ASP.NET MVC Pros  More control over your html and JavaScript  Separation of Concerns (SoC)  SEO friendly  Test Driven Development (TDD)  Highly flexible & customizable  Not RAD  No rich controls ASP.NET MVC Cons
  • 6. MVC Pattern Who uses it? • .NET has Spring.NET and MonoRail • Java has Swing, Struts, Grails and others • Perl has Catalyst, Gantry, Jifty and others • PHP has Zend, Zoop, Agavi and others • Python has Django, Gluon, Pylon and others • Ruby has Ruby on Rails • Apple has cocoa and cocoa touch for objective-c [Mac, iPhone]
  • 7. ASP.Net MVC Overview • ASP.NET MVC? • ASP.Net MVC Execution Process • ASP.Net MVC 4 Project Structure
  • 8. ASP.Net MVC Overview ASP.Net MVC Architecture M Model V View C Controller • Representation of domain data • Business Logic • Persistence mechanisms • User Interface • The representation of Model • An intermediary between Model and View • Application’s Brain (Handle user requests, bind Data, return views)
  • 9. ASP.NET Dynamic Data ASP.NET WebForms ASP.NET MVC Presentation Runtime ASP.NET Core It’s not a replacement for asp.net webforms, it’s a new flavour of asp.net ASP.Net MVC Overview ASP.Net MVC?
  • 10. ASP.Net MVC Overview ASP.Net MVC Execution Process
  • 11. ASP.NET MVC 4 Project Structure 1. App_Data folder is the physical store for data. 2. Content folder keeps files such as scripts, CSS, images, etc 3. Controllers folder is the location for controllers. 4. Models stores classes that handle application domain logic. 5. Scripts folder is for script files. By default, this folder contains AJAX script files and the JQuery library. 6. Views is the recommended location for views. View files use .cshtml extension.
  • 12. Routing R => the hidden characterMVC +R 1. Maps incoming URLs to the application and routes them to the right Controller’s Action method to execute them 2. Happens in RegisterRoutes function in the global.asax file
  • 13. Routing Don’t settle for… /ProductsDetails.aspx?CategoryID=123 When you can easily have… /Product/Details/123/ Or whatever else makes sense…
  • 16. Model • It’s the core of your application • A place for business logic, data access, Validation ... etc • You can use your favorite data access technology with ASP.NET MVC [LINQ to SQL, Nhibernate, Entity Framework …etc]
  • 17. Controller [C] Controls the flow of application execution
  • 18.  Controller is a class containing a set of action methods.  Responsible for o Handling user interaction o Working with the models o Selecting a view to render o Sending model and information to a particular view o Making decisions for security, UI, redirects ... etc.  The ASP.Net MVC requires the names of all controllers to end with the suffix "Controller“ e.g. HomeController, LoginController & ProductController Controller
  • 19. Actions Rules: 1) Must be a public method 2) Cannot be a static method 3) Cannot be an extension method 4) Cannot be a constructor or property 5) Cannot have generic type. 6) Cannot contain ref or out parameters. Controller Controller Actions An action is a method on a controller that gets called when you enter a particular URL in your browser address bar.
  • 20. Each action returns ActionResult which can be • ViewResult => HTML and markup. • EmptyResult => no result. • RedirectResult => redirection to a new URL. • JsonResult => json result that can be used in an AJAX application. • JavaScriptResult => JavaScript script. • ContentResult => text result [and wraps any non ActionResult return Type]. • FileContentResult => downloadable file [with the binary content]. • FilePathResult => downloadable file [with a path]. • FileStreamResult => a downloadable file [with a file stream]. A controller action always returns an ActionResult Controller Controller Actions Note: all public methods of a controller class considered as action methods, if you don’t want a public method to be an action, mark it with [NonAction()] attribute
  • 22. View • Responsible for presentation, look & feel, formatting, sorting … etc. • Interacts with model but doesn’t make any decisions • No logic should go there • No View State, No Server Controls • HTML Helper functions • Can be strongly typed • Takes the view data from the controller Tips: • @ is equivalent to response.write() • @{} is used to execute code • Use @Html.Encode() method to prevent script injection
  • 25. • Html.ActionLink() • Html.BeginForm() • Html.CheckBox() • Html.DropDownList() • Html.EndForm() • Html.Hidden() An HTML Helper is just a method that returns a string. View HTML Helpers • Html.ListBox() • Html.Password() • Html.RadioButton() • Html.TextArea() • Html.TextBox() e.g.
  • 26. References •Official website http://asp.net/mvc •Source Code http://codeplex.com/aspnet •Blogs o Scott Guthrie http://weblogs.asp.net/scottgu o Rob Conrey http://blog.wekeroad.com o MVC Store Front http://blog.wekeroad.com/mvc-storefront o Phil Haack http://haacked.com o Scott Hanselman http://hanselman.com o Stephen Walthler http://weblogs.asp.net/stephenwalther
  • 27. Nitin Sawant Software Engineer Email:nitin@nitinsawant.com T h a n k y o u www.twitter.com/nitinjs www.linkedin.com/in/nitinjs