Like me, you might have been surprised that the foundation series didn’t have a chapter on the MVC pattern. I’m no fan of the existing page model (I actually think it’s horrible), and I’ve successfully used MonoRail on a few projects, so it would have made for a good topic. My reasons for not including something on MVC were simple: we were and continue to be flooded with MVC information (as though it’s a brand new invention), and I didn’t think I could explain MVC using MonoRail effectively (I find it has a steep learning curve). I considered using RoR, but figured that would confuse people even more.
Hopefully though, if you’re a fan of the foundation series, you’ve already downloaded the learning application which puts the theory to practice using ASP.NET’s MVC framework. So, what do I think about ASP.NET MVC? Overall I’ve been very impressed. I can’t think of a good reason for starting a new project using the WebForms model – or MonoRail for that matter (sorry). If you’re an ASP.NET developer, it’s really a no brainer.
I do have two major issues with it though. First, if you come from almost any other MVC framework (MonoRail, Django, RoR, Akelos, etc…) you might be expecting an actually Model framework – instead you get an empty Model folder. In other words, the MVC framework doesn’t add anything to the .NET O/R Mapping / DAL story. From Microsoft’s point of view this makes sense, since they feel that they are already offering solid solutions – DataSets, SqlDataSources, LINQ to SQL, Entity Framework. Truth be told, this is fine with me, as it lets me use NHibernate. I just think, given what the other MVC frameworks offer, it’s a little dishonest – you’ll end up disappointed if you’re expecting to be able to do this out of the box:
public class Car : ActiveRecord
My real problem though is simply that neither C# nor VB.NET lend themselves all that well to view logic. Jeff Atwood actually just blogged the same criticism. Jeff uses RoR to highlight the problem. I don’t fully agree. I won’t say that RHTML is great, but I will say that it’s far better than C# or VB.NET. I think views need a specialize language – I’m sure that anyone who’s done some significant work in either RoR or Django would agree. There are solutions available now – NVelocity and Boo (I assume you could use it with the MVC framework?), but I’m just going to trudge along with C# until IronRuby is a viable solution.
Aside from that, everything is pretty solid – routes work great, helper methods are adequate (they’re starting to add more and more), and testing is actually doable – I haven’t run into any problems, but from what I’ve read things aren’t 100% perfect yet (either way, it’s a huge step up from WebForms).
So, to recap. MVC good. WebForms Bad. C# in views less than ideal. Empty Model folder = M. Oh, and download the learning application!.