• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
ASP.Net MVC
 

ASP.Net MVC

on

  • 6,513 views

 

Statistics

Views

Total Views
6,513
Views on SlideShare
6,509
Embed Views
4

Actions

Likes
1
Downloads
233
Comments
0

1 Embed 4

http://www.slideshare.net 4

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    ASP.Net MVC ASP.Net MVC Presentation Transcript

    • Introduction To ASP.Net MVC New Framework in Old Style Ahmad ABU ARJA MCP, MCAD, MCSD, MCTS, MCPD Enterprise
    • Do you feel like this each time Microsoft announces a new technology?
    • MVC Pattern • What is it? • How does it work? • Who uses it ? …“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 Pattern What is it? • MVC - Acronym for Model/View/Controller • MVC is a architectural pattern • Invented by Trygve Reenskaug [1978] • Originally used as an architectural pattern for GUIs. • The first implementation of MVC was as part of the Smalltalk-80 class library.
    • MVC Pattern How does it work? Domain Logic Presentation Data Persistence [look and feel, formatting, sorting, etc.] Model Read only View Controller Flow Control
    • 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]
    • ASP.Net MVC Overview • ASP.Net MVC? • ASP.Net MVC Project Structure • ASP.Net MVC Execution Process
    • ASP.Net MVC Overview ASP.Net MVC? • A new web project type for ASP.NET. • It’s not a replacement for asp.net webforms, it’s a new option [flavor] • No more “postbacks” and “ViewStates” • Built on top of ASP.NET Advantages • Clean URLs and HTML • More control over your html and JavaScript • Friendly URLS • More easily Testable Framework. • Great integration within ASP.NET • All ASP.Net providers still work [Membership, Session, Caching, etc] • Extensible and Pluggable [Support replacing any component]
    • ASP.Net MVC Overview ASP.Net MVC Project Structure App_Data folder is the physical store for data. Content folder keeps files such as scripts, CSS, images, etc Controllers folder is the location for controllers. Models stores classes that handle application domain logic. Scripts folder is for script files. By default, this folder contains AJAX script files and the JQuery library. Views is the recommended location for views. Views use .aspx, .ascx, and .master files.
    • ASP.Net MVC Overview ASP.Net MVC Execution Process Create MVC Perform Request request routing handler Create Execute Invoke action controller controller Render View
    • DEMO • Create New ASP.Net MVC Project • Investigate ASP.Net MVC Structure
    • Routing MVC +R R => the hidden character
    • Routing • Maps incoming URLs to the application and routes them to the right Controller’s Action method to execute them Default Routing /Products /Products/Categories /Products/Detail/34
    • 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] Controlling the flow of application execution
    • Controller  Controller is a class consisting of 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 quot;Controller“ e.g. HomeController, LoginController, or ProductController
    • 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. 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 A controller action always returns an ActionResult Action return 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]. 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 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 Tips: • <%= %> is equivalent to response.write() • <%# %> is used to execute code • Take care of Html.Encode() method to prevent script injection
    • View HTML Helpers An HTML Helper is just a method that returns a string. e.g. • Html.ActionLink() • Html.ListBox() • Html.BeginForm() • Html.Password() • Html.CheckBox() • Html.RadioButton() • Html.DropDownList() • Html.TextArea() • Html.EndForm() • Html.TextBox() • Html.Hidden()
    • 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
    • Ahmad R. ABU ARJA Senior Software Developer email: a.abuarja@live.com www.twitter.com/abuarja www.linkedin.com/in/abuarja Thank you