Why I Just Don't Get ASP.NET MVC?

By leen3o on Feb 15 2009 | 4 Comments

So before I start I thought I would say yes, I pretty much am an ASP.NET novice compared to most but I have built quite a few website's in ASP.NET VB & C#, most recently my sports social network PlayerFind which is where I was really toyed between learning MVC or just sticking to my webforms!  I had the idea for PlayerFind at the beginning of last year and as I started and stopped building it I heard more and more about ASP.NET MVC and being an ASP.NET nut I was very eager to give it a whirl, but after really reading into it I just don't get it! So here's a list of things I read that make the MVC way of doing things much better to use, and why this dumb novice just doesn't get it.

Unit Testing

One of the big things I have read all over blogs is unit testing, I'm still not completely sure how it works but I really like the sound of it and how useful it could be (Especially to me). Then I stumbled on NUnit & NUnitASP, both open source unit testing software that I can use with webforms? So I can use Unit testing without having to learn MVC?

URL Routing

Obviously like most people who are into their SEO, this was one of the main draws to going down the MVC route (Get it... hehehe.. route...anyway) and getting the pretty / search engine friendly URLS - But now I see the Routing has been moved out of MVC and you can use it with webforms?

Total Control Of HTML

This I did understand initially, I'm actually a front end dev and moved late into ASP.NET - so having control of my XHTML and using CSS is very important.  As I started looking at the way MVC worked (Firstly I just thought man this is the old ASP way of doing things) and secondly I thought why are people not just using the Repeater or ListView control? As in essence isn't that what they both do?  Just loop through the records AND giving you total control of your HTML?  In addition I created an SEO friendly / non-postback paging control for my ListView on an older project where it used a value in a QueryString to determine what page to show AND how many rows to display?

Complete New Learning Curve

Even after all this time the voice in my head keeps telling me to try it, but the rest of me just needs convincing! As its a whole new learning curve (And it took me long enough to get where I am now) I just don't want to spend months learning something that in the end is actually takes me longer to build applications and really is no better than using the old school route of webforms.

Anyway, I just thought I would voice a novices opinion on ASP.NET MVC as it only seems to be the clever folk talking about it - I would love to be truly convinced that MVC is the way to go but at the moment I really just don't get it.

kick it on DotNetKicks.com

Post info

Tags:
Categories: ASP.NET

Comments

Derik Whittaker on 2/15/2009 8:41 AM What the MVC brings to the table is total control and good design principles.  Yes testability and URL routing our heavily promoted, but to be honest that is only part of the story.

Based on the MVC pattern you will required to separate out your application logic into smaller parts that are more fitting to SOLID principles.  Because the view does not support postback/viewstate it really must be 'dumb'.  Meaning that you should push ONLY the data which needs to be displayed to the view and the view will render it.

The controller is your traffic cop.  This will be used to handle requests from the view and will simply be used for either conditional (if/when statements) or directional (what view to render) logic.  It should not be responsible for hitting the DB or any other external services, this is the job of your abstracted business layer.

The Model allows you to very simply and easily create a clean layer for controlling your domain logic.

When you put these parts together you start to build cleaner, more separated code.  This allows for faster changes and more stability.

Keep in mind, that MVC does not fit every situation and is not meant to be a replacement for WebForms.
lee on 2/15/2009 9:15 AM Thanks for the comment Derek, I learnt ASP.NET from the following tutorials on the ASP.NET site.

www.asp.net/Learn/data-access/tutorial-01-vb.aspx

This made me split my logic up using webforms, creating a data access layer and a business layer etc from the start.. But from what you say and what I have read I understand MVC seperates things further.  But there is such a huge push for MVC at the moment, I still cannot see any benefits for someone like me to invest the time into learning it?

You say MVC does not fit every situation, how do you define which should used when?  And if thats the case why are the main .NET people like stephen walther (http://stephenwalther.com/blog/) just pushing MVC?
Derik Whittaker on 2/15/2009 10:02 AM It does not fit every scenario at this point because of the lack of RAD UI controls from people like Infragistics and DevExpress.  Many corporate apps need/want the 'slick drag and drop' tools.  If this is their need then they should not use MVC because there are none at this point.

As for me, I am 100% MVC at this point.  I find it easier and simpler than webforms.

In terms of benefits, to me it is pretty clear cut.  Using the (or any) MVC framework creates clean and clear cuts of separation in my code base.  I can have a view that has no knowledge of how it was generated or how it will be used.  I can have a controller which only knows it needs to handle requests and push data to a view.  And all of this allows me to build complex apps with very little effort.

r4 software on 7/2/2009 9:10 AM Hi,

The ASP.NET MVC Framework is definitely worth a look since it addresses aspects of programming that are extremely important for developers and their productivity such as code reusability, testing, and separation of presentation and business logic concerns. At the same time, an early look at the MVC Framework may generate good feedback to Microsoft and help them to deliver a better and richer product in full accordance with the community expectations and needs.