Understanding ASP.NET MVC Code (For Aspiring Architects) - #3

 Alik Levin    This post is a digest of the Understanding Models, Views, and Controllers (C#). It helps to quickly understand the generated code when creating ASP.NET MVC project in Visual Studio.

Resources 

ASP.NET MVC Project in Visual Studio

  • Three folders created:  Models, Views (ASPX pages sit here), Controllers
  • Urls are SEO friendly (/Home/About)
  • No direct correspondence between URL and the page.

Routing

  • Requests mapped to Controller's actions
  • ASP.NET Web Forms are content centric
  • ASP.NET MVC is logic centric
  • ASP.NET Routing maps request to action.
  • Routing is registered in Global.asax
  • Controllers

    • Controls user interaction (flow) with ASP.NET MVC application.
    • Derive from Controller class.
    • Exposes actions that can return ActionResult.
    • Any public method is action (WARNING: can be invoked freely via URL).
    • A controller should only contain the bare minimum of logic required to return the right view or redirect the user to another action (flow control).

    Views

    • Create folders by Controllers names.
    • Create sub-folders to reflect views that Controller handles.
    • View is ASPX page that inherits from System.Web.Mvc.ViewPage
    • View should contain only logic related to generating the user interface.

    Models

    • An MVC model contains all of your application logic that is not contained in a view or a controller.

    Related Materials

    This post is made with PracticeThis.com plugin for Windows Live Writer

    Published 06 April 09 11:52 by alikl
    Filed under: ,

    Comments

    # irocon said on April 7, 2009 10:41 AM:

    Very informative, Thanx! Still trying to get the hang of this MVC stuff. I must say MVC is very intimidating before you try it.

    # alikl said on April 12, 2009 12:34 AM:

    irocon,

    happy to hear it was helpful for you ;)

    New Comments to this post are disabled

    Search

    This Blog

    . My Personal Blog .

    .Net Performance How To's

    .Net Security How To's

    Design Patterns

    Impactful

    Lifecycle Phases

    Popular

    Tools

    Syndication

    Page view tracker