ASP.NET MVC: A Step Backwards?

Thursday, November 12th, 2009 at 22:14

Web Development, , , ,

ASP.NET MVC LogoAfter a couple of well deserved days off work this week, I’ve been looking into the new(ish) alternative to WebForms for ASP.NET, ASP.NET MVC:

Just to give some brief background; ASP.NET MVC sits at the same layer that WebForms do currently, and does not replace ASP.NET, but rather offers an alternative to the traditional ASP.NET development that we’re all used to.  There are some excellent overview articles and a other information at the the ASP.NET MVC site.  I’m not going to go into any real detail regarding the technology here, but suffice to say that essentially the aim of ASP.NET MVC is to bring control back to the web developer whilst enforcing proper segregation of model, view and controller aspects.

Note:  From this point I’m going to refer to ASP.NET MVC as just plain old MVC.  I realise MVC is actually just a design pattern, but for the sake of my fingers please excuse me.  I’d also like to say that while I have a fairly high level of expeirence developing WebForms applications, but I haven’t actually tried MVC yet.  So some of my views may well be unfounded.

The more I read about the differences between the two approaches to ASP.NET development, the more I’m conflicted.  On the one hand I love the concept of MVC for things like:

  • Simplicity.  It’s nice to have a new platform that provides so much control back to the developer.  I also love the thought of getting rid of all the crap that WebForms generates which messes up my anally beautifully crafted mark-up.
  • Segregation.  No more business logic hiding in code-behind files, although it’s worth noting that there’s nothing to stop you breaking the convention to do this.

However; on the other hand I feel like MVC has the following issues:

  • Control reuse.  As mark-up is generated in a far more “manual” fashion, you appear to loose the ability to drag-and-drop controls to pages.  This is addressed somewhat by what Microsoft refer to as “HTML helper methods” (essentially just extensions of the static Html class), but I’m still unconvinced.
  • Spaghetti code.  Because MVC moves away from the code-behind model of WebForms (although again, doesn’t restrict it), your “views” end up being full of in-line code which – in my opinion – just looks horrific.  This actually is the biggie for me.

I think the reason I struggle so much, is that – coming from a commercial development background – I can’t see the benefit to switching away from WebForms to use MVC as it stands currently.  Largely the feeling I get with development tasks in a commercial setting – especially those which aren’t customer facing – is that it’s generally more important that web applications do the right thing than that they look right.  So some of the identified issues with WebForms in relation to bad mark-up, or display issues etc don’t really feel prevalent enough to warrant the additional time it would require to develop something using MVC.  Yes; I realise you gain more control, and get closer to what purists would claim was “pure” web development (more akin to PHP, Ruby etc), but I’m just not convinced that this is enough to warrent the additional development time.

I guess the important point to note however; is that WebForms isn’t being replaced by MVC.  Instead Microsoft are now offering an alternative to what we’re more used to while still exposing the wide and rich ASP.NET framework libraries.  I’m also still very keen to give it a go, and there are still some things which I think look really interesting.  I just wish there was a better alternative to using in-line code in the views!

Edit:  After reading a very informative blog post, it looks like there may well be light at the end of the code-spaghetti filled tunnel for MVC in the form of Spark.

15 Comments »


15 Comments on “ASP.NET MVC: A Step Backwards?”

  1. 1 Tweets that mention The Curly Bracket » Blog Archive » ASP.NET MVC: A Step Backwards? -- Topsy.com said at 4:13 PM on November 13th, 2009:

    [...] This post was mentioned on Twitter by Elijah Manor and Martin Jansen, Doug Copestake. Doug Copestake said: Blogged ASP.NET MVC: A Step Backwards?: http://tinyurl.com/y8ethey [...]

  2. 2 Travis said at 4:14 PM on November 13th, 2009:

    Your forgetting the most important part of MVC, *Unit* testability and TDD. Without TDD, MVC is nothing. Without TDD, your better off sticking with Webforms.

  3. 3 Jon Kruger said at 4:40 PM on November 13th, 2009:

    I’d encourage you to look into MVC some more. In my opinion, it is WAY easier to use than WebForms, my code is much cleaner, and I get things done a lot faster than I did with WebForms. Developing for the web is fun again (except for dealing with IE).

  4. 4 ChrisNTR said at 4:56 PM on November 13th, 2009:

    You’ve pretty much hit MVC/Webforms spot on. If you’ve already got an existing system using webforms and the users don’t care about the markup – then there will be very little gain in switching over to MVC apart from learning a new framework for fun. As with anything, you use the best tool for the job. :)

    Spark is a great view engine and I 100% recommend it.

  5. 5 Doug said at 5:16 PM on November 13th, 2009:

    Thanks for the comments. I will definetely give it a go, and Spark certainly looks like one of the more readable view engine sources.

    Regarding TDD; I guess the reason I haven’t spotted the advantages MVC brings on that front because I always make a point of segregating my business logic away from the view code using WebForms. I guess the big advantage with MVC is that it goes some way to enforcing that without having to really try :)

  6. 6 Nick Kirkes said at 5:17 PM on November 13th, 2009:

    It’s good to hear what knee-deep WebForms folks are saying about MVC (that’s where I came from too), but you hit the nail on the head with your initial caveat, and it’s hard to form an educated opinion without jumping in feet first. The “tag soup” that you reference, while prohibitive to many that haven’t dug in and built an MVC based app, is a non-issue when done right. Of course there’s plenty of rope to hang yourself, but with a keen eye for when/where code should be implemented as custom helpers (or separate user controls), you can dramatically reduce the complexity of the aspx markup. The benefits of the rest of framework far outweigh this potential pitfall. And as you noted, you can always swap out your view engine to something like Spark that helps mitigate the concern in it’s own way. I haven’t missed the drag/drop server controls at all (ok, maybe a little), and I haven’t had a need to go back to WebForms since I started working with MVC at v1 Preview 2.

    Good on you for exploring and forming an early opinion. I’d be curious to read what your thoughts are after spending some quality time with the framework.

  7. 7 uberVU - social comments said at 5:31 PM on November 13th, 2009:

    Social comments and analytics for this post…

    This post was mentioned on Twitter by Dougcope: Blogged ASP.NET MVC: A Step Backwards?: http://tinyurl.com/y8ethey...

  8. 8 Neil Kerkin said at 5:46 PM on November 13th, 2009:

    It seems to be a common consensus that if you’re putting anything more than the most basic code into your views, then you are doing MVC wrong.

    All business logic should happen in the controller and you should move any “view” logic into helpers.

    Though you lose drag-and-drop (a good thing), control reuse is provided in many ways, js libraries, RenderPartial, Partial Requests, etc.

    You mention spark but there plenty of alternatives http://codebetter.com/blogs/jeffrey.palermo/archive/2008/01/27/mvccontrib-now-offers-four-4-alternative-view-engines-for-asp-net-mvc.aspx

    And this is pretty much the theme (and major benefit) of MVC in general, if you don’t like something feel free to use something else or write your own

  9. 9 Doug said at 5:55 PM on November 13th, 2009:

    I must admit, I didn’t quite realise how interchangeable the view engines where, or how many alternatives there where around.

  10. 10 Jen said at 8:38 AM on November 14th, 2009:

    I prefer MVC. It is quicker and easier to use :) Stick with it!

  11. 11 Tim Wingfield said at 5:51 PM on November 14th, 2009:

    Rather that write a huge comment here, I added it to my own blog: http://blog.timwingfield.com/2009/11/aspnet-mvc-step-in-right-direction.html

    I think you’re headed in the right direction, and if you’re like a lot of folks I know that made the switch, about halfway through your first MVC project you’ll have that, “Why didn’t I do this before?” moment. :)

  12. 12 ASP.NET MVC Archived Blog Posts, Page 1 said at 4:13 AM on November 18th, 2009:

    [...] to VoteASP.NET MVC: A Step Backwards? (11/12/2009)Thursday, November 12, 2009 from http://www.thecurlybracket.comThe more I read about the differences [...]

  13. 13 Danny said at 9:12 PM on November 18th, 2009:

    Doug,

    I highly recommend reading Steve Sanderson’s Pro ASP.NET MVC book from Apress. He’s also in the UK and is very
    knowledgeable in MVC. His book walks you through a complete example.

    There are others as well including Simone Chiaretta, Keyvan Nayyeri, Maarten Balliauw, Jeff Palermo and Dino Esposito.

  14. 14 Steve said at 3:54 AM on November 25th, 2009:

    I hope as a young developer, that you spend some time to look at other languages. You’ll see a majority of the well proven and time-tested frameworks use a mvc approach.

    “you appear to loose the ability to drag-and-drop controls to pages”

    I don’t know many web developers that drag and drop much nowdays. With code snippets, you can easily generate a ‘textbox’. To really get the control you need in the html today, I rarely even work in designer. Intellisense is very well done, working in the source provides more control without worry of the designer messing up the html, etc…

    The amount of declarative syntax is .. if anything .. less in mvc than in webforms.

    “Spaghetti code.”

    Like ? Don’t assume because someone doesn’t know good practices and code technics to assume it’s ‘spaghetti code’.

    Mvc has controls that emit html. That is all webform controls do.

    If anything, I’ve seen more ‘spaghetti code’ in hundreds of lines of ‘OnDataBind’ datagrids in code behind than anything close to the mvc.

    If anything, mvc helps control the amount of logic in UI. I highly recommend you look at the html helpers. They provide a clean way to introduce ‘controls’ with logic where it belongs and proper code reuse.

    Thanks for your blog post.

  15. 15 Surge said at 3:15 AM on June 24th, 2010:

    good article, good points, but with time you will change your opinion.


Leave a Reply