Getting to grips with MVC

A few posts back I listed goals I wished to achieve over the next six months. Currently I am looking in to the Microsoft MVC Framework. I have started by watching Scott Hanselmans' four screen casts over at www.asp.net, these give a pretty good introduction of the framework and what you get out of the box with Visual Studio 2008 with the MVC framework extensions installed. There is also a screen cast from MIX08 here which covers most of the same material, but works as a once over refresher. Jeff Palermo also has a good demonstration on dnrTV. I have found in the past that it is easier to learn about something if you have a set of questions to ask, the natural process of researching the answers leads to a better understanding of the subject matter. So here are a few simple questions I have asked myself.

Some q and a's on MVC

1. Why bother with MVC?

If you are developing large enterprise web applications which rely a lot on view state, do not use MVC. If however you are developing a relatively small web application, perhaps a social network type application, then MVC may be for you. However you can mix and match by implementing MVC within an asp.net web application. Also if you are wanting to develop web applications using a TDD approach, then it may help you as unit testing is fully supported.

2. Does it get rid of the dreadful post-back?

Yes. The ASP.Net MVC framework does not implement post-back, view state or use the web forms event driven lifecycle. This will be a relief to some people, however if you want to store any temporary data between page requests, you need to find another mechanism to do so.

3. What is REST?

REST stands for REpresentational State Transfer and is a mechanism to transfer data via HTTP without utilising any messaging layers such as sessions or cookies.  REST applications are generally Client-server, Stateless, Cacheable, and Layered. It can use the HTTP methods of POST, GET, PUT and DELETE to perform the basic CRUD commands for data manipulation. So a URL of /blogs/GET/today can represent a command to retrieve blogs updated today. Microsoft MVC uses a technique called routing which can basically replace the URL above to something more user friendly such as /blogs/show/today.

4. Is it a pattern or a framework?

MVC is a pattern, is well documented and has in fact been around since at least the early 80's. ASP.Net MVC is a framework developed solely for asp.net from Microsoft.

5. Do I still need AJAX, if so how?

ASP.Net MVC works with or without AJAX so implementing AJAX is entirely up to the developer. When the product goes to RTM it will fully support the Microsoft ASP.Net AJAX out of the box, however the developer is free to use any other AJAX framework. Nikhil Kothari has an excellent article where he delves in to MVC Ajax in more detail.

6. Is it just for .net 3.5 or can I use it for 2.0?

The ASP.Net MVC is currently only supported on 3.5. In Visual Studio 2008, selecting a new project in 3.5 gives you the choice to create an ASP.Net MVC project with or without an additional unit test project.

7. Can I run it on IIS6 or is it for IIS7?

You have two options when running it on IIS6, you can either use a wildcard mapping to the asp.net isapi dll or you can map the .mvc extension to it. The former will impact performance of the website, the latter will give less desirable URL including a .mvc extension in the URL. You can employ a rewriter dll such as isapi_rewrite as described here.

Asking myself these simple questions has given me the opportunity to look in to MVC and I have cleared up some of my own perceptions of the whole MVC thing. It has also given me more questions to research such as how to store tempory data without using session or cookies. I hope to expand on these questions in future posts.

My next step is to install the thing and have a good play around with it.

Very basic I know, but it has helped me and it may help someone else.

Here are some links to sites which I have found useful.

Introduction to REST
http://www.viddler.com/Roebot/videos/10/

A Brief Introduction to REST
http://www.infoq.com/articles/rest-introduction

Chapter 4. What is MVC?
http://www.jcorporate.com/expresso/doc/edg/edg_WhatIsMVC.html

Model-View-Controller
http://www.webopedia.com/TERM/M/Model_View_Controller.html

MVC Overview
http://quickstarts.asp.net/3-5-extensions/mvc/MVCOverview.aspx

3 Comments

  • MVC is USELESS bacause:
    1) No REACH user controls without page state support. MVC web is DEAD on arrival!
    2) Easy teastability coming to REGULAR web forms, wait for framework 4. If you can not wait use custom MVP.
    3) In M$ one hand does not know what other does, buy YHOO, sell MVC, buy MVP, sell all, buy MOSS... blaa

    NOF said!

  • @bobo - Thanks for your comments. Personally I am just looking into MVC to see what it is all about, I guess time will tell wether it is a success or not. I didn't know about testing for regular web forms in framework 4. Do you have any web links I can look at?

  • REST and testing for regular web forms in framework 4 info is from MS employees mouth (not officially)

Comments have been disabled for this content.