ASP.net MVC CodeCamp Presentation

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    ASP.net MVC CodeCamp Presentation - Presentation Transcript

    1. ASP.net MVC Owen Evans Developer, Xero
    2. or
    3. Welcome to the new (old) way
      • MVC – Model-View-Controller
        • About architectural separation
        • Not a new pattern, first attributed to Trygve Reenskaug, working in smalltalk at Xerox Parc
        • Convention over configuration
        • Less to think about (no page object model)
        • Easier to unit test
    4. Lots of MVC Frameworks
      • Some well known:
        • Rails, Merb, Monorail, Grails, Spring MVC Framework, Dojo, Django, Silverstripe, Flex, Swing,
      • Others not so
        • Check Wikipedia for links to lots of frameworks
    5. The MVC pattern Controller View Model
    6. MVC vs. Classic ASP.net
      • ASP.net Classic
      • ASP.net MVC
    7. Model
      • The computer model. The representation of the system within your application domain
      • Business objects, services, data access etc
      • The application core
    8. Controllers
      • Direct all the action of a request
      • Make calls to models to gather data
      • Sends business object and information to a particular view.
      • Makes decisions for security, UI, redirects etc.
      • Provides the glue between the mental model and the computer model
    9. A Basic Controller
      • public class HomeController : Controller
      • {
      • public ActionResult Index()
      • {
      • var message = someService.GetAMessage()
      • return View(message);
      • }
      • }
      • Interacts with the model and gets a message
      • Puts the message to the default view
      • Only one action/view for this controller
    10. View
      • Responsible for displaying a given expectation of data.
      • Will interact with model but shouldn’t make decisions over what entities to display, shouldn’t make CRUD actions etc.
      • Purely about representing the mental model of the system.
      • Not restricted to aspx, can also use Nhaml, Brail, XSLT to name but a few, just implement a ViewEngine if you want your own view syntax
    11. A Basic View
      • <%@ Page Language=&quot;C#&quot; MasterPageFile=&quot;~/Views/Shared/Site.Master&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;Index.aspx.cs&quot; Inherits=&quot;Basic_MVC_Project.Views.Home.Index&quot; %>
      • <asp:Content ID=&quot;indexContent&quot; ContentPlaceHolderID=&quot;MainContent&quot; runat=&quot;server&quot;>
      • <h2><%= Html.Encode(ViewData[&quot;Message&quot;]) %></h2>
      • <p>
      • To learn more about ASP.NET MVC visit <a href=&quot;http://asp.net/mvc&quot; title=&quot;ASP.NET MVC Website&quot;>http://asp.net/mvc</a>.
      • </p>
      • </asp:Content>
      • Relies on a master page
      • Just displays the data in the ViewData store
    12. Putting the R in MVC
      • Routing is part of the major power of MVC
        • Many URLs can link to the same controller, unlike code behinds which have a 1-1 link with .aspx pages, controllers can have multiple views
        • Controllers are usually grouped around conceptual objects within the domain
          • Tasks, Posts, Products
    13. The ActionResult
      • The key to actions is ActionResult which has many implementations
        • ViewResult: Renders the specified view to the response.
        • EmptyResult: Does nothing. Returned if the action method must return a null result.
        • RedirectResult: Performs an HTTP redirect to the specified URL.
        • RedirectToRouteResult: Given some routing values, uses the routing API to determine the URL and then redirects to that URL.
        • JsonResult: Serializes the specified ViewData object to JSON format.
        • ContentResult: Writes the specified text content to the response.
    14. ActionFilter
      • Attribute based interception of action calls
      • Can hook into calls:
        • OnActionExecuted
        • OnActionExecuting
        • OnResultExecuted
        • OnResultExecuting
      • Useful for logging, security, caching etc.
    15. Extras
      • Ajax made easy
        • You can just return a Json result and JavaScript can eval the response to get the result.
      • REST made easy
        • Routing makes creating rest web services just a case of routing to the correct action
    16. Caveats
      • This talk was based on Preview 4, Preview 5 was released on Friday and has a couple of minor changes
      • Preview code still, API’s are subject to change.
      • Still a lot of community work to do to create helpers, utilities etc..
    17. Questions?
      • Ask Scott Hanselman…….
      • Contact me:
        • http://www.bgeek.net,
        • owen@bgeek.net,
        • http://www.twitter.com/buildmaster
    18. References
      • ASP.net MVC Official Site http://www.asp.net/mvc/
      • MVC Xerox Parc http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-index.html
      • Scott Gu, Phil Haack, Scott Hanselman, Rob Conery http://weblogs.asp.net/scottgu/ http://haacked.com/Default.aspx http://www.hanselman.com/ http://blog.wekeroad.com/
      • MVC Contrib Project http://codeplex.com/MVCContrib

    + buildmasterbuildmaster, 2 years ago

    custom

    512 views, 0 favs, 1 embeds more stats

    Slides from Code Camp Auckland 2008, presentation o more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 512
      • 492 on SlideShare
      • 20 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 28
    Most viewed embeds
    • 20 views on http://bgeek.net

    more

    All embeds
    • 20 views on http://bgeek.net

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories