views:

339

answers:

4

One of the common questions asked regarding ASP.NET MVC is why should you use it over ASP.NET Web Forms? The answer generally includes ViewState and clean URLs, amongst others. Towards the end you'll find a blurb about using the right tool for the job and that they serve different purposes. However, I don't believe I've ever seen what those purposes are. So, when would you actually choose ASP.NET MVC over ASP.NET Web Forms, or ASP.NET Web Forms over ASP.NET MVC?

+4  A: 

http://weblogs.asp.net/shijuvarghese/archive/2008/07/09/asp-net-mvc-vs-asp-net-web-form.aspx

check that blog !

Bottom line "separation of concerns"

Broken Link
+12  A: 

You don't choose ASP.Net MVC over ASP.Net, because ASP.Net MVC still is ASP.Net. You do choose ASP.Net MVC or ASP.Net Web Forms, and there are lots of good reasons to do that:

  • Easier to get control over your HTML
  • Easier to do unit testing
  • Few "Gotchas"

On the other hand, Web Forms do have a few points in their favor:

  • Easy to put simple CRUD/business apps together extremely fast
  • Hard to beat ViewState performance in local LAN enviroment
  • Easy to learn forms paradigm

The result is that if you're building business apps in a corporate LAN environment (which honestly is still most web developers), Web Forms is really great. In that sense Microsoft really knows their market. But if you're building an app for the public internet, you might want MVC so you can test thoroughly and be sure your pages aren't bloated with un-necessary viewstate or javascript data.

Joel Coehoorn
I'm curious about your statement about "hard to beat viewstate performance in local LAN environment" - can you clarify? Are you suggesting it's network burden is less when local so you don't have to worry about network performance as much?
Matt
Viewstates can get very large, and this is definitely a performance issue when the server is not local.
Steven Sudit
The absolute network burden is the same: a 60K viewstate is 60K everywhere. The _relative_ network burden is very differetn: 60K to a local network is nothing, but 60K uploaded for every postback over even a consumer broadband connection can make your pages appear much slower than they are.
Joel Coehoorn
Also, if your viewstate is absolutely HUGE, you're doing something wrong.
Joel Coehoorn
Take issue with "Easy to learn forms paradigm". (Compare request/response with the forms page lifecycle.) Also: Webforms leaves little control to the developer to manage complexity.
Steve Horn
+3  A: 

I'll give you a couple purposes, with clear advantages.

  • If your purpose is a public facing website that will be banking on traffic, use MVC. It is optimal for search engine optimization.

  • If your purpose is an enterprise web-application that acts like a desktop app, I would lean towards web forms, since state management and compartmentalization of your resources into underlying server controls offers huge advantages if used correctly.

womp
Whether or not the site will be easily recognized by search engines is something that is frequently left out of design considerations. Good point on it being an MVC benefit.
Kivus
A: 

The biggest problems facing developers is managing complexity and keeping code "clean". MVC gives the developer the reins to leverage OOP to tuck away complexity and make code easy on the eyes.

Webforms will be faster to develop in the short term, but it doesn't lend itself to long term sustainability in terms of maintenance and growth.

Steve Horn