My Thoughts on ASP.NET’s MVC

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!.

This entry was posted in Foundations. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

8 Responses to My Thoughts on ASP.NET’s MVC

  1. Werner says:

    I’ve used Monorail extensively and webforms in both consulting and private capacities.

    I prefer the Monorail / Windsor approach. It clean, clear seperation of concerns and once you get over the initial learning curve your mind really takes off to another level.

    Granted VS does not have intellisense etc for NVelocity but I don’t see that as a deal breaker. I have been able to combine Monorail and JQuery to build a web based application that works and functions like Mac Desktop (as a proof of concept).

    Once you understand the paradigm of IoC and how you can use it in Monorail you are able to build pluggable modules that completely control their own behavior within the framework, making your application very easy to maintain and extend without major impact on your core.

  2. Jason says:

    I would love to see something akin to Cold Fusion’s CFML. I often find myself writing condition statements in C#. CFML includes tagged condition logic. My views are effective, but not visually appealing, which was one of the nicer things about webforms. As awful a framework as it is, it’s certainly very very readable.

  3. brad says:

    yeah, I love how they gave us a great migration path for the 600 or so pages we have now too. Just like COM to .Net. Microsoft SUCKS.

  4. karl says:

    I don’t know why I’m not a fan of MonoRail, its just has never been my favorite. Maybe it’s because I was learning RoR at the same time and I found myself comparing the two. I do think it has a worse learning curve than ASP.NET MVC – I realize that’s largely because of a new view language, which I advocate (I’m full of contradictions!!). I couldn’t get NVelocity to work well for me in VS.NET 2008 (no highlighting, no intellisense, no resharper goodness). I’d actually call MVC more polished (MonoRail might have really improved over the last year or so).

    I realize other view languages are available. I have used NVelocity, and I’ve looked at Brail. I am willing to try them both (it didn’t make much sense in the context of the learning application as it just would have confused people). My point though is that most people will use ASP.NET MVC with C# or VB.NET – which I don’t think is ideal. I hope people look at alternatives, but I’ve resigned myself to accepting that until Microsoft officially supports something, it won’t be mainstream (MVC itself is proof enough for me).

  5. Josh says:

    I have to agree with you about the lack of easy ORM in MVC. I know they want to be ORM agnostic, but that is really one of the great things about Rails. It’s all just ready to go.

    In the MVC app I’m building, I’m using LINQtoSQL, and that hasn’t been too bad. I’ve had to change a few things here and there, and add some things. Luckily it’s the code generation is really easy to extend, as it uses all partial classes. It’s not nearly as nice as the ActiveRecord library in rails, but it’s getting the job done.

  6. Chris says:

    Out of curiousity, why wouldn’t you use MonoRail again?

    “If you’re an ASP.NET developer, it’s really a no brainer”

    This isn’t a complete thought. It should be more like:

    If you’re an ASP.NET developer who realizes that WebForms blow, then it’s a no brainer; if you’re an ASP.NET WebForms developer and don’t get the whole “MVC” fad[read sarcasm], then it’s a no brainer, you’re stuck at your government job for the rest of your carreer …

    [emphasis on developer versus webforms developer]

  7. Mike Chaliy says:

    You can visit to look how MVCFramework works with third party view engines like Brail, NHaml. NVelocity and more…

  8. dario-g says:

    I disagree with in one point. MVC give’s you real a clean separation of concerns. You can use different view engines and also different data access frameworks, eg. Sooda, NHIbernate, etc. You may feel free, that’s why Model folder is empty. You can put into this what do you wan’t.

    Maybe OR/M’s should have some wrapers to easly use in MVC.NET?