SlideShare ist ein Scribd-Unternehmen logo
1 von 35
ASP.NET MVC CRUSH COURSE ERDEM ERGİN
MVC Pattern – What is it? MVC - Acronym for Model/View/Controller Invented by TrygveReenskaug[1973 - 1978] Originally used as an architectural pattern for GUIs. The first implementation of MVC was as part of Smalltalk-80  class library.
MVC Pattern – How does it work? The Controller asks the Model for data The request hits the controller Model 2 1 3 Controller User The Model gives the data back to the Controller The controller formats the data and passes them to the View View 4 5 The view renders the HTML that needs to be sent to the client 3
MVC Pattern – Who uses it? .NET has Spring.NET, 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]
MVC FrameworkHistory Based on Python 1970S …. 2003 RoR { ASP.NET MVC } 2009.3 MVC1  2010.4 MVC2
ASP.NET MVC ,[object Object]
 No more “postbacks” and “ViewStates”
 Built on top of ASP.NETAdvantages ,[object Object]
More control over your html and JavaScript
Friendly URLS
More easily Testable Framework.
All ASP.Net providers still work [Membership, Session, Caching, etc]
Extensible and Pluggable [Support replacing any component],[object Object]
ASP.NET MVC Execution Process
DEMO Create New ASP.NET MVC Project Investigate ASP.NET MVC Structure
Routing MVC+R R => the hidden character
ASP.NET MVC Routing URL Patterns Setting Default Values for URL Parameters Adding Constraints to Routes Scenarios When Routing Is Not Applied How URLs Are Matched to Routes Accessing URL Parameters in a Routed Page ASP.NET Routing and Security ASP.NET Routing versus URL Rewriting
Model [M] Validation
Controller [C] Controlling the flow of application execution
ASP.NET MVC Controller Controller is a class consisting of a set of action methods.  Responsible for  Handling user interaction Working with the models Selecting a view to render Sending model and information  to a particular view 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
ASP.NET MVC Controller A controller action always returns an ActionResult What if I return an object ?? Action return ActionResult which can be ,[object Object]
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]. Note: all public methods of a controller class consideredas action methods, if you don’t want a public method to be an action, mark it with [NonAction()] attribute
ASP.NET MVC Controller Filter
View [V]
ASP.NET MVC View Responsible for presentation, look & feel, formatting, sorting … etc.  Interacts with model but shouldn’t make decisions  No logic should go there Code Behind exists but not recommended No View State, No Server Controls HTML Helpers Takes the view data from the controller Can be strong typed   Can be extended by implementing View Engines Always build your views !!!
An HTML Helper is just a method that returns a string. • Html.ActionLink() • Html.BeginForm() • Html.CheckBox() • Html.DropDownList() • Html.EndForm() • Html.Hidden() • Html.ListBox() • Html.Password() • Html.RadioButton() • Html.TextArea() • Html.TextBox() e.g. ASP.NET MVC View
Extensibility
The default ASP.NET MVC Pipeline 21

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCLearnNowOnline
 
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.Ni
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVCRichard Paul
 
Unit testing and MVVM in Silverlight
Unit testing and MVVM in SilverlightUnit testing and MVVM in Silverlight
Unit testing and MVVM in SilverlightDevnology
 
Real-world Model-View-ViewModel for WPF
Real-world Model-View-ViewModel for WPFReal-world Model-View-ViewModel for WPF
Real-world Model-View-ViewModel for WPFPaul Stovell
 
Spring MVC Architecture Tutorial
Spring MVC Architecture TutorialSpring MVC Architecture Tutorial
Spring MVC Architecture TutorialJava Success Point
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architectureravindraquicsolv
 
ASP .NET MVC Introduction & Guidelines
ASP .NET MVC Introduction & Guidelines  ASP .NET MVC Introduction & Guidelines
ASP .NET MVC Introduction & Guidelines Dev Raj Gautam
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJSTroy Miles
 

Was ist angesagt? (20)

Struts2
Struts2Struts2
Struts2
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
ASP .net MVC
ASP .net MVCASP .net MVC
ASP .net MVC
 
Struts 1
Struts 1Struts 1
Struts 1
 
MSDN - ASP.NET MVC
MSDN - ASP.NET MVCMSDN - ASP.NET MVC
MSDN - ASP.NET MVC
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVC
 
Introduction to struts
Introduction to strutsIntroduction to struts
Introduction to struts
 
Unit testing and MVVM in Silverlight
Unit testing and MVVM in SilverlightUnit testing and MVVM in Silverlight
Unit testing and MVVM in Silverlight
 
Jinal desai .net
Jinal desai .netJinal desai .net
Jinal desai .net
 
Real-world Model-View-ViewModel for WPF
Real-world Model-View-ViewModel for WPFReal-world Model-View-ViewModel for WPF
Real-world Model-View-ViewModel for WPF
 
Spring MVC Architecture Tutorial
Spring MVC Architecture TutorialSpring MVC Architecture Tutorial
Spring MVC Architecture Tutorial
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Struts ppt 1
Struts ppt 1Struts ppt 1
Struts ppt 1
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
 
ASP .NET MVC Introduction & Guidelines
ASP .NET MVC Introduction & Guidelines  ASP .NET MVC Introduction & Guidelines
ASP .NET MVC Introduction & Guidelines
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJS
 
Struts2
Struts2Struts2
Struts2
 
Spring MVC Basics
Spring MVC BasicsSpring MVC Basics
Spring MVC Basics
 

Ähnlich wie Asp.net mvc

Inside asp.net mvc framework
Inside asp.net mvc frameworkInside asp.net mvc framework
Inside asp.net mvc frameworkCiklum Ukraine
 
Inside ASP.NET MVC framework
Inside ASP.NET MVC frameworkInside ASP.NET MVC framework
Inside ASP.NET MVC frameworkCiklum Ukraine
 
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...SoftServe
 
ASP.NET MVC Fundamental
ASP.NET MVC FundamentalASP.NET MVC Fundamental
ASP.NET MVC Fundamentalldcphuc
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To MvcVolkan Uzun
 
Controllers & actions
Controllers & actionsControllers & actions
Controllers & actionsEyal Vardi
 
Simple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnanSimple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnanGigin Krishnan
 
Build your website with angularjs and web apis
Build your website with angularjs and web apisBuild your website with angularjs and web apis
Build your website with angularjs and web apisChalermpon Areepong
 
CTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCCTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCBarry Gervin
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCSunpawet Somsin
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Patterngoodfriday
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs WorkshopRan Wahle
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014Ran Wahle
 

Ähnlich wie Asp.net mvc (20)

Inside asp.net mvc framework
Inside asp.net mvc frameworkInside asp.net mvc framework
Inside asp.net mvc framework
 
Inside ASP.NET MVC framework
Inside ASP.NET MVC frameworkInside ASP.NET MVC framework
Inside ASP.NET MVC framework
 
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
 
ASP.NET MVC Fundamental
ASP.NET MVC FundamentalASP.NET MVC Fundamental
ASP.NET MVC Fundamental
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To Mvc
 
Controllers & actions
Controllers & actionsControllers & actions
Controllers & actions
 
Simple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnanSimple mvc4 prepared by gigin krishnan
Simple mvc4 prepared by gigin krishnan
 
Build your website with angularjs and web apis
Build your website with angularjs and web apisBuild your website with angularjs and web apis
Build your website with angularjs and web apis
 
CTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCCTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVC
 
Asp.Net MVC Intro
Asp.Net MVC IntroAsp.Net MVC Intro
Asp.Net MVC Intro
 
ASP.MVC Training
ASP.MVC TrainingASP.MVC Training
ASP.MVC Training
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
MVC 4
MVC 4MVC 4
MVC 4
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Pattern
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 
Spring MVC 3.0 Framework
Spring MVC 3.0 FrameworkSpring MVC 3.0 Framework
Spring MVC 3.0 Framework
 
ASp.net Mvc 5
ASp.net Mvc 5ASp.net Mvc 5
ASp.net Mvc 5
 
ASP.NET MVC Extensibility
ASP.NET MVC ExtensibilityASP.NET MVC Extensibility
ASP.NET MVC Extensibility
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
 
J2EE pattern 5
J2EE pattern 5J2EE pattern 5
J2EE pattern 5
 

Asp.net mvc

  • 1. ASP.NET MVC CRUSH COURSE ERDEM ERGİN
  • 2. MVC Pattern – What is it? MVC - Acronym for Model/View/Controller Invented by TrygveReenskaug[1973 - 1978] Originally used as an architectural pattern for GUIs. The first implementation of MVC was as part of Smalltalk-80 class library.
  • 3. MVC Pattern – How does it work? The Controller asks the Model for data The request hits the controller Model 2 1 3 Controller User The Model gives the data back to the Controller The controller formats the data and passes them to the View View 4 5 The view renders the HTML that needs to be sent to the client 3
  • 4. MVC Pattern – Who uses it? .NET has Spring.NET, 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]
  • 5. MVC FrameworkHistory Based on Python 1970S …. 2003 RoR { ASP.NET MVC } 2009.3 MVC1 2010.4 MVC2
  • 6.
  • 7. No more “postbacks” and “ViewStates”
  • 8.
  • 9. More control over your html and JavaScript
  • 11. More easily Testable Framework.
  • 12. All ASP.Net providers still work [Membership, Session, Caching, etc]
  • 13.
  • 15. DEMO Create New ASP.NET MVC Project Investigate ASP.NET MVC Structure
  • 16. Routing MVC+R R => the hidden character
  • 17. ASP.NET MVC Routing URL Patterns Setting Default Values for URL Parameters Adding Constraints to Routes Scenarios When Routing Is Not Applied How URLs Are Matched to Routes Accessing URL Parameters in a Routed Page ASP.NET Routing and Security ASP.NET Routing versus URL Rewriting
  • 19. Controller [C] Controlling the flow of application execution
  • 20. ASP.NET MVC Controller Controller is a class consisting of a set of action methods. Responsible for Handling user interaction Working with the models Selecting a view to render Sending model and information to a particular view 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
  • 21.
  • 24. JsonResult => json result that can be used in an AJAX application.
  • 26. ContentResult => text result [and wraps any non ActionResult return Type].
  • 27. FileContentResult => downloadable file [with the binary content].
  • 29. FileStreamResult => a downloadable file [with a file stream]. Note: all public methods of a controller class consideredas action methods, if you don’t want a public method to be an action, mark it with [NonAction()] attribute
  • 32. ASP.NET MVC View Responsible for presentation, look & feel, formatting, sorting … etc. Interacts with model but shouldn’t make decisions No logic should go there Code Behind exists but not recommended No View State, No Server Controls HTML Helpers Takes the view data from the controller Can be strong typed Can be extended by implementing View Engines Always build your views !!!
  • 33. An HTML Helper is just a method that returns a string. • Html.ActionLink() • Html.BeginForm() • Html.CheckBox() • Html.DropDownList() • Html.EndForm() • Html.Hidden() • Html.ListBox() • Html.Password() • Html.RadioButton() • Html.TextArea() • Html.TextBox() e.g. ASP.NET MVC View
  • 35. The default ASP.NET MVC Pipeline 21
  • 36. The default components URL Routing: Parses the URL, andinstantiate the MvcHandler Controller Factory Takes URL parameters, create controller via reflectionbased on Controllername Action Invoker Invokes the actionbased on thename, with the filtersbefore and after ViewEngine WebFormsviewengine Template Renders a TextBoxalmostforeverything HtmlHelper Has a bunch of standardmethods
  • 37. Routingextensibility RouteConstraint Validatesrouteparameterswith code RouteHandler Defineshow the requestmustbehandled
  • 38. Controller Extensibility ControllerFactory ResponsibleforcreatingControllers ActionInvoker Invokesanaction, basedonly on itsname ActionMethodSelectorAttribute Helps the actioninvoker decide whichactiontoinvokewhen the nameisnotunique Controller The base classforevery controller ActionResult Decideshowtosend the output to the user
  • 39. ActionFilterExtensibility AuthorizationFilter Makessure the currentrequestisallowed ActionFilters Executedbefore or after the actionexecutes ResultFilters Executedbefore or afteranactionresultexecutes
  • 40. Binding/ValidationExtensibility ModelBinder Populates the actionmethodparametersfrom the request ModelValidator Provider Retrieves the validationrules Server-sideValidationRules The actual server-side validationrule
  • 41. ViewExtensibility ViewEngine The service thattransforms in HTML the data for the user HtmlHelpers Utility functionsthathideaway the generation of some HTML markup or JavaScript code Client-sideValidationRules Client-sidevalidationrules ModelMetadata Provider Retrieves the metadataneededfor the templatedhelpers Custom Templates Renders the html toedit/display specifictypes
  • 43.
  • 44.
  • 45. Server-sideValidationRules WHAT: Definehow a propertyisvalidated in the server side validation DEFAULT: Required, Length, wrong type WHY: Add your own rules Write a new ValidationAttribute Implement the IsValid method Apply attribute to your model Demo
  • 46. Client-sideValidationRules WHAT: Definehow a propertyisvalidated in the client-side validation DEFAULT: Client-sidecounterparts of the default server-side validators WHY: Addyourownvalidators
  • 47. Client-sideValidationRules First make a server-side validator Makevalidationlogic in JavaScript Writeadaptertopushvalidationrulesto client-side Registervalidationfunction via JS Registeradapter in Global.asax Demo
  • 48. Base Controller WHAT: The base class for every Controller DEFAULT: Default implementation of helper methods WHY: Extend if you want to enforce you own conventions Override Controller YourcontrollersoverridefromBaseControllerinsteadof Controller Demo
  • 49. HtmlHelpers WHAT: Utility functions that hide away the generation of HTML markup or JavaScript code DEFAULT: Html.TextBox, Html.Encode, Html.Partial, … WHY: “If there is an if, write an Helper” Add new methods as extension methods Demo