Learning ASP.NET MVC

I’ve found there is A LOT of information on the net about learning the MVC framework. I thought it might be helpful for others to read about my experiences while I’m learning.

So, my starting point: http://asp.net/MVC Scott Hanselman has a really fun and interesting presentation regarding a OSS website he’s developed called Nerddinner.com

I’ve had some experience with TDD and ASP.NET webforms from a previous project I was working on and we were using a Model-View-Presenter pattern which as far as I can see is pretty much the same as MVC.

The View – This is a dumb portal to communicate information to the user

The Controller – This communicates information to the view and translates it to and from the Model. It is generally unit tested and could communicate with the view via a View Model.

The Model – Contains business logic, stores and retrieves data in a database and is really the concrete information regarding your software project. This is also the data that you may need to mock to check your controller handles user input correctly.

More buzz words I needed to look up/I feel are never explained particularly well:

  • View Engine – A method of displaying information to the user. See wikipedia for a better description
  • Routing policy – Rather than using Viewstate, URLs can tell the controller what to display
  • Dependency Injection – DI allows you to inject objects into a class, instead of relying on the class to create the object itself. (Microsoft)
  • IOC
    • “Inversion of Control – IOC specifies that if an object requires another object, the first objects should get the second object from an outside source such as a configuration file. This makes testing easier.” (Microsoft)
    • Car requires seats. Car should get seats from factory (not the driver/user).
  • URLRoutingModule – Guesses the page you are trying to reach. No match means it falls back to the default IIS settings. In MVC a URL does not equal a page. Browser requests are mapped to controller actions.
  • MvcHandler – Selects the controller that will handle the request
  • JSON – JavaScript Object Notation

The Controllers Execute method, invokes an action method associated with the controller, which in turn, receives user input, prepares a response and returns the requested type. The built in result types are:

  • ViewResult (which renders a view and is the most-often used result type),
  • RedirectToRouteResult,
  • RedirectResult,
  • ContentResult,
  • JsonResult, and
  • EmptyResult

ASP.NET Routing

An ASP.NET Web Forms application is content-centric. An ASP.NET MVC application, in contrast, is application logic centric. It uses a route table to work out which controller to use and associated input data. What I’m not sure about yet is how to save data back to the Model through the view.

Using JSON – Another post for that I think!

Using Meta Data – data that describes data!


Microsoft. (n.d.). MVC Overview. Retrieved from http://asp.net: http://www.asp.net/learn/mvc/tutorial-01-cs.aspx

6 responses to “Learning ASP.NET MVC

  1. Ole Gunnar Borstad

    I will follow your blog, Pete! MVC looks cool, I want to learn that as well!

    Good luck with the blog!

  2. Awesome to see that you have started blogging – and great post providing an entry point for someone getting into ASP.NET MVC.

    As always I do have something to “pick” on. It’s kind-of important to differentiate MVC and MVP – if not part of the benefit of patterns are lost as we do not have a shared understanding of what they mean.

    ASP.NET MVC (as the name suggest) is built entirely around the MVC pattern, a pattern that works really well for stateless web applications.

    The main difference between the MVP we used at Vital and how MVC is built is the order the different players (M, V, C/P) come into play.

    In ASP.NET everything start when a HTTP request lands on the server and the routing engine figures out which controller to invoke. The controller then calls out to the model, get some data and pass it off to the view. So the order is like this:

    HTTP Request -> Routing -> Controller -> Model -> Controller -> View -> Outoput

    In MVP we have built the pattern around the different nature of ASP.NET WebForms. A request comes in and lands at the View first. A method on the View is invoked based on the control causing the postback. Then control is passed off to the Presenter, which will do some work, before passing stuff back to the View. So the order in MVP becomes like this:

    HTTP PostBack -> View -> Presenter -> Model -> Presenter -> View -> Output

    If you remember, in MVP we even create the presenter in the View code behind.

    So – to repeat the “subtle” difference is the order. And since the Controller steps in so early in ASP.NET MVC, this flavor of web based MVC is some times refereed to as “Front Controller”, as the controller sits in front.

    For a more complete description of the differences check out this article: http://msdn.microsoft.com/en-us/magazine/dd252940.aspx

    Check out the section “Model2: A Web Variation of MVC” and the section “The MVP Pattern” and you’ll see the difference quite clearly 🙂

    Again, looking forward to following your ASP.NET MVC learning experience 🙂

    • That’s an excellent observation and clarifies the point for me! Why have I not seen that before! Thanks for sharing, I’ll try to keep on the steep side of the learning curve

  3. I don’t know enough about the hand-rolled MVP pattern you were using before, but it seems there is a similar framework called WebFormsMVP too (http://webformsmvp.com/) discussed on the latest Hanselminutes podcast.

    Yet another ASP.NEt web framework to learn 😉

    • Good catch Alex. The WebFormsMVP is done by two mates of mine from Melbourne (Damien and Tatham). Awesome guys who really gets web development. Would really recommend checking out this ASP.NET presentation from the same guys from REMIX09: http://www.microsoft.com/australia/remix/videos/?vid=v20

      If you have to learn it or not depends on your project. If you got an ASP.NET Web Forms project, the WebFormsMVP project could be a great addition. It can easily added page by page (it’s not an all or nothing solution), so may be something for you guys at Bennet if you got a large WebForms code base.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s