views:

4596

answers:

5

I have seen the ASP.NET community buzzing about MVC. I know the basics of its origin, and that there are many sites (unless I am mistaken, stack overflow itself) based on ASP.NET MVC.

From everything I have heard and read about MVC it seems to be the future of ASP.NET development. But since I don't usually dabble in .NET web development I am left wondering the following: when is it appropriate to use MVC and when is it not, and why? Examples of great (and terrible) use of MVC would be fascinating.
Though I realize there are other implementations of MVC view other languages like RoR I am more interested on its impact for .NET programmers.

If this has already been gone over, my apologies!

+14  A: 

Here are my 2 cents about MVC for web applications. For the sort of GUI apps for which MVC was originally intended, "listener" code was required, so that the UI could be updated when events altered the model data.

In MVC for the web this is unnecessary, you get your listener for free: the web server, and the HTTP request IS the event. So really MVC for the web should be even simpler. Indeed, it could be boiled down to the Mediator pattern, where the Controller mediates between the model and the view.

There are two things that there is a lot of confusion about. Regardless of conventional "wisdom":

Frameworks != MVC

Database Data != "Model"

"Full stack" web development frameworks typically add lots of features, and may or may not be MVC-oriented at their core. One of the features many frameworks add is database access or object relational mapping functionality, and because frameworks and MVC get confused, subsequently database data and the model facet of MVC also get confused. The model can generally be viewed as the underlying data for the application, but it does NOT have to come from a database. A good example might be a wiki, where the underlying model/data consists of file revision data, for instance, from RCS.

Hope this helps and I'm sure others will have plenty to add.

George Jempty
Just add that ASP.NET MVC is somehow Model agnostic. The model is just an object or a collection while in other MVC frameworks, like RoR, a model base implementation is provided following in that case the ActiveRecord pattern.
Marc Climent
Upvoted for the notes saying that MVC is not a framework and that the model is not the database!
macke
+7  A: 

ASP.NET MVC isn't the future of ASP.NET development it is just a new way of developing websites with ASP.NET. Microsoft have made it clear they will continue supporting and improving both WebForms and MVC in the future.

I cannot think of any websites, were it would not be appropriate to use MVC. You could also argue the same for WebForms.

Whether you choose one over the other is a personal choice, and would depend on the development team's experience and preferences.

I personally would never go back to WebForms development after using MVC on several big projects. WebForms in my opinion places an unnecessary abstraction layer over http and html. For quick prototypes you can get something cobbled together quicker with WebForms, but after that the complication of the abstraction makes things harder rather than easier. The only compelling reason to use WebForms in my opinion is the rich level of 3rd party controls that are currently available. But you can mix WebForms and MVC, so its easy enough to get the best of both worlds.

Andrew Rimmer
+1  A: 

I work in a shop that has both ASP.NET and MVC applications. I think originally I was biased toward web forms because I worked with them from several years, but after working on a few MVC projects I prefer it.

Something to consider, however, is that if you have a team of experienced web form developers initial progress in an MVC application will be a slower because of the learning curve, so if the timeline for a project is very tight it might not be the best time to transition.

Aside from that I can't think of any situations where I'd prefer web forms over MVC at this point.

Nate
+2  A: 

Based on my own experience, I can tell you that if you don't have any Winforms or Webforms background, you may feel more comfortable under the MVC umbrella because you are not "expecting" anything from the ASP.NET Webforms world.

On the other side, as a recommendation, I encourage you to check out other MVC frameworks like Django or RoR that are more mature to "be water" on the MVC way of thinking. I'm happy with ASP.NET MVC but looking other solutions helps you to understand better the paradigm behind the framework.

Marc Climent
+13  A: 

I would say one very compelling scenario to use MVC is if you have a group of experienced .NET developers who dont have experience with WebForms.

Coming from that situation myself (very little web experience) I found it I was much more productive and comfortable using MVC over WebForms.

I found it very hard to pickup WebForms due to the aforementioned abstraction - (I think proof of WebForms complexity is I have never met anyone who I would consider a WebForms "guru" i.e. knows the Page Lifecycle off by heart/Data Binding back-to-front etc.).

Using MVC actually allowed me to use my .NET and software experience without needing to heavily invest in learning the WebForms framework. Not only that but I got a much better understanding of HTTP, and this I think would allow higher quality solutions.

IMHO MVC allows you to factor code much better than WebForms, so I think developers with lots of "patterns" experience will be more comfortable in MVC.

Schneider
+1. Good point!
Sorin Comanescu