Over a million developers have joined DZone.

ASP.NET MVC - Is The Grass Really Greener?

·
There are three ways now to write a web site in ASP.NET:
  • Use Classic ASP model with everything in the ASPX file and only use HTML controls without the runat="server" attribute
  • Use the Web Forms model
  • Use the new ASP.NET MVC model

Each have their own benefits that need to be weighed carefully prior to moving forward with a design.  So, what does MVC give us that we didn’t already have in either classic ASP or Web Forms?

ASP Model

The classic ASP model has as it’s primary benefit the fact that it is a familiar model to most web developers and allows us to write light weight code.  See my post about why classic web developers have trouble with ASP.NET for a larger discussion on this topic.  Other than it being familiar, you might also use this for a simple web page that doesn’t really do anything (static content) or a "one off" application that have very few pages.  However, we all know that "one off" pages end up being larger applications where an application benefits from a defined architecture.  So, the only good reason for using this model would be that it is a lighter weight model than what we might otherwise have with ASP.NET’s Web Form model.

Web Form Model

The Web Form model primary benefit over the other two models is that it allows you to create an application quickly with a semi-predefined architecture.  The down sides are that it tends to have more on the client side than it should and you really have to understand event based programming to get it to do everything you’d want it to do.  Something traditional web programmers are not familiar with and struggle with when they first meet ASP.NET Web Forms.

To be clear, most of the detractors to the Web Form model can be eliminated if you fully understand  how it works.  For example, you could purchase or build an HttpModule that handles state management on the server instead of in a hidden form field, or you could simply turn off state management.

If time to market is your most critical determining factor, ASP.NET will probably still be your choice.

ASP.NET MVC Model

So, what does ASP.NET MVC give us that the others don’t?  Primarily it gives us a more granular separation of concerns and eliminates the overhead associated with Web Form controls.  Not that we can’t use them, but we don’t have to use them to take full advantage of the model.

For people coming out of a Java/JSP web development background, ASP.NET MVC is going to look a lot more familiar than either classic ASP or the Web Forms model.

However, for those of us already comfortable with Web Forms development, I’m afraid MVC is going to seem like a step backwards.

This isn’t to say that it shouldn’t be used.  Just that there is a learning curve associated with this new model as there is with any model.

If you need a high performance web site and are willing to put time into learning this new model, ASP.NET MVC might just be for you.

One type of web application that might benefit from this new architecture is one which is primarily AJAX based using a lot of JSON calls to web services.

That is, because you are avoiding postbacks, you wouldn’t be using Web Form controls anyhow.  In this case, you’d either need to roll your own architecture or you’d want to adopt one that fits what you are doing on your site.  I always opt for using something someone else has created.

If you’ve been using the classic model, you really should drop that and use MVC instead.  Classic is architectureless (is that a word?) and having an architecture is always better than no architecture.

Do you really need it?

Microsoft has made it pretty clear that ASP.NET MVC isn’t for everyone.  It is a way of programming a web site that has specific benefits to a specific class of programmers and/or organizations.  It is not THE way to program ASP.NET.

My fear for us as programmers is that many lead programmers will convince their organizations to move to this new model simply because it is new and therefore better.  Because they want it on their resume.  Rather than because there is a strong business case for moving to this new architecture.

Be careful to choose the right tool for the job.  Not what you know and certainly not what you want to put on your resume.  Just because it is new, doesn’t mean it is greener.

Topics:

Published at DZone with permission of Dave Bush, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}