• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Introduction to ASP.NET MVC
 

Introduction to ASP.NET MVC

on

  • 5,126 views

Introduction to ASP.NET MVC

Introduction to ASP.NET MVC
Agenda
What's MVC?
What's ASP.NET MVC?
How it work?

Statistics

Views

Total Views
5,126
Views on SlideShare
5,121
Embed Views
5

Actions

Likes
1
Downloads
195
Comments
1

1 Embed 5

http://www.slideshare.net 5

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

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • thanks
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Main purpose of mvc is to isolate business logic from user interface pros - Better maintain - Testable - Cleaner code
  • Testability - Framework provides interface-base  easy to mackable Pluggable - Every component can easy replaced or customize (view replaced with ironPython) - Easy to use dependency injection design pattern (unity, spring) Friendly URL - Can build app for search engine friendly Existing ASP,NET feature still available - All exist asp.net feature still available ex: Master.Page, User Control, Session, Memberdhip - But ViewState and page life cycle are not support Full control of HTML - Write only html - no viewstate Open source - under MS-PL license
  • Demo from empty project Show create view and run Show ViewData and run Demo TDD hello world
  • Controller is responsible for handling incoming request - All public method that implement by Controller class, It can be invoke from web via url.
  • Controller is responsible for handling incoming request - All public method that implement by Controller class, It can be invoke from web via url.
  • Demo new template project Modify routing default to commentary Create model Commentary Create Commentary controller Create View Show F5 Create Method Details Use Model.Subject
  • Demo new template project Modify routing default to commentary Create model Commentary Create Commentary controller Create View Show F5 Show feature for HTML helper Show JSON JsonRequestBehavior.AllowGet
  • Show validation with statemodel Show validation with anotation in serverside Show validation with client
  • Using ModelState Class => Encapsulates the state of model binding to a property of an action - method argument, or to the argument itself
  • Uses the ‘Page Controller’ pattern . Each page has a code - behind class that acts as a controller and is responsible for rendering the layout . Uses the ‘Front Controller’ pattern. There is a single central controller for all pages to process web application requests and facilitates a rich routing architecture

Introduction to ASP.NET MVC Introduction to ASP.NET MVC Presentation Transcript

  • Introduction to ASP.NET MVC
  • Agenda
    • What's MVC
    • What's ASP.NET MVC
    • Goals of ASP.NET MVC
    • How does it work?
  • What's MVC View Model Controller
    • Defines application behavior
    • Maps user action to model
    • Select view to response
    • Represent enterprise data
    • Business rules that govern access/update data
    • Render content of model
  • What's ASP.NET MVC
    • New framework from Microsoft that builds on top standard ASP.NET engine
    ASP.NET Web Form ASP.NET MVC Core standard ASP . NET engine Microsoft .NET Framework
  • Goals of ASP.NET MVC
      • Testability
      • Pluggable
      • Friendly URLs (REST URL)
      • Existing ASP.NET feature still available
      • Full control of HTML
      • Open source
  • ASP.NET MVC
      • ASP.NET MVC 1.0 (Dec, 2008)
      • ASP.NET MVC 2.0 Beta (Nov, 2009)
  • ASP.NET MVC
      • .NET Framework 3.5
      • Visual Studio 2008 (service pack 1)
        • Download ( asp.net/mvc )
      • Visual Studio 2010 (included)
  • Demo: Hello World
      • Controller is responsible for handling incoming request
      • Routing system decides how URLs map into particular controllers and actions
    How does it work? Action in controller Controller http://localhost:1725/ Hello / ActionTest
      • Component is first hit by a request
      • The rules are configured in Global.asax
    Routing public static void RegisterRoutes(RouteCollection routes) { routes.MapRoute( "Default", "{ controller }/{ action }/{ id }", new { controller = "Home", action = "Index", id = "" } ); } http://localhost:1725/ Product / Show / 1
  • Demo: Model with Strong type
  • Request Flow Request View Controller Model HTTP Select View HTML Routing Select Controller
  • Demo: HTMLHelper
      • Provide method for creating HTML control
      • Support Strong-type
    HTML Helper <%= Html. TextBoxFor (model => model. Body ) %> <input type=“text” name=“ Body ” id=“ Body ” />
      • Request variable
      • Action method parameter
      • ModelBinder
    Handling post request Public ActionResult Create() { string subject = Request.Form[“Subject”]; } Public ActionResult Create( string Subject ) { // do something } Public ActionResult Create( Commentary commentary ) { // do something }
  • Demo: Form & Validation
  • Validation Define Validation in Model Server Side Validation Client Side Validation ModelState Class to keep state of model Data Annotation Model Binder Java script
  • Summary RESTful URL Complex URL F ull control over   HTML Clean HTML Event - driven programming (Drag n’ drop) Design for testing Cannot test easily Separation of Concerns Combines code and view ASP.NET MVC ASP.NET WebForms
  • Q & A