views:

2866

answers:

29

Let's say that you will start a new Asp.Net web site/application tomorrow. What your choice between WebForms and MVC, and why?

+2  A: 

ASP.NET MVC because I want to learn how to use it.

Michael Kniskern
+1  A: 

I would like to go with MVC. I always seam to be fighting the abstraction when I work with WebForms.

To use WebForms effectively you actually need to know more about how the web works than if you use something like PHP. I find myself using <asp:Literal instead of <asp:Label to avoid putting a <span> around the text and running labs to figure out the order of events, etc.

jrcs3
Using <asp:Literal is the right approach. The only reason to use <asp:Label is when specifying the AssociatedControlId="someTextBox" value to turn it into a real xhtml label.
adolfojp
@adolfojp: Or when you want to assign a cssclass to it :)
Zyphrax
+18  A: 

I would choose MVC simply because it's designed to be testable and mock'able. That would be the major factor in my decision.

WebForms are much more difficult to Unit Test because they're rooted in several concrete classes that are difficult, it at all possible, to Mock. These include HttpContext, HttpResponse, HttpRequest and HttpCookie.

MVC is designed to be testable and it's API greatly facilitates doing so.

Good article on the testability of MVC: http://dotnetslackers.com/articles/aspnet/ASPNETMVCFrameworkPart2.aspx

JaredPar
Agreed, also MVC here.
Matt Olenik
+1  A: 

I would currently choose ASP.NET MVC for 2 reasons: 1) I want to learn to master it. 2) There is already a great community forming around ASP.NET MVC and everyone seems to have very positive entergy regarding it's use. I can't wait to see where it all ends up and I want to be part of it.

JPrescottSanders
"great community forming around it with lots of energy" I was thinking about this too!
Click Ok
I think your reasons are wrong. Do you think community around Webforms is any less powerful?
Cyril Gupta
Gupta: My answer had nothing to do with the Webforms community, it was based on what I'm witnessing in the ASP.NET MVC community. I like the energy that everyone has regarding MVC, and I think that energy will help make it a great option when building web apps.
JPrescottSanders
A: 

More info here: http://stackoverflow.com/questions/30067/

Juan Manuel
Not exactly. That post talks about migration and I'm speaking about starting a project from scratch.
Click Ok
If you read past the title: "a project that's starting in a few days"
Juan Manuel
+13  A: 

If I were starting today I would probably still stick with webforms because of the volume of knowledge and resources surrounding it.

That said I really want to give MVC a shot and as others have mentioned the excitement within the community means it wont take long before there is a lot of support for it.

Luke Lowrey
"volume of knowledge and resources surrounding it." - nice point!
Click Ok
+1. Same reason I'm still in webforms for the time being.
fung
there is a rule I read somewhere that for Microsoft you should always wait for 2.0. I was getting into the MVC hype until I remembered my own experiences with trying to move from ASP to .NET 1.0/1.1. I'll switch when MVC 2.0 is released in a year. IMHO
Brian Boatright
fyi, now I'd go with MVC
Luke Lowrey
+75  A: 

MVC baby! And JQuery!

Edit: OK, it's fair enough to say my response warrants a little more info.

I'd choose MVC for the following reasons:

  1. I have worked in Rails and found it highly productive. ASP MVC has borrowed so much from Rails that it feels like a direct port in some ways (and that's a good thing in my mind).
  2. AJAX is important, but I hate the Microsoft "Atlas" approach to AJAX (whatever the product name is these days). If you're going to do AJAX, you need to understand the HTML and the JavaScript. Frameworks that hide that from you are hurting you more than they are helping you (IMO).
  3. JQuery has taken over the world it seems in terms of JavaScript frameworks. ASPMVC is well-integrated with it. I want to learn it, so there's great alignment here.
  4. The whole "control" model is a neat idea, but it is more complicated than it appears on the surface. For example, look around on SO for questions about how a UserControl can find its highest level containing control and so forth. The control hierarchy abstraction has leaks in it. Grids are great if they do what you want out of the box, but it's very very hard to customize them to do something they weren't made to do. And the best grid controls on the market (the ones that are highly customizable) are large, bloated, overly complicated beasts. Maybe that shows us that we should drop back down to HTML and let loops in our views do that kind of thing for us.
  5. I believe I can build complete, beautiful apps in ASPMVC much faster than in ASP.Net (and I've got some years of ASP.Net under my belt). Look at StackOverflow ... built quickly on ASPMVC with JQuery, and it's fast, scalable and a joy to use IMO.
  6. Oh, and it's completely open source! It is ok to read the source code, blog about it, and even modify then redistribute it!
Charlie Flowers
Enthusiastic! But why?
Click Ok
NOW it is a argument! Thanks! :)
Click Ok
@Charlie Flowers: Good answer. +1
Kb
Completely agree on every point. I am using MVC on 3 production projects and couldn't be happier with it. Well, maybe a little, but it's great.
Stuart Branham
Can't agree more! Dont forget to check out other opensource frameworks for GUI work like extjs.com and http://mochaui.com/demo/
AlexanderN
My impression is that MVC locks you into Linq: true? If so, are you comfortable being locked in like that?
Mark Brittingham
Agreed, especially on #4. I worked in extensively with WebForms for years before I had a thorough understanding of how everything worked with regards to the page lifecycle, viewstate et al. It is ridiculously easy to get into all sorts of infuriatingly complicated and obscure trouble if you're trying to customize or abstract anything control related.
Daniel Schaffer
I want to work on MVC. But not getting chance. Currently I'm satisfying myself with web forms :(
Ismail
I have been using MVC since November 09, and it is everything I had hoped and more. And boy was I ever right about JQuery. It is so fantastic I *want* to work in JavaScript.
Charlie Flowers
+1  A: 

it really depends on the project, since i havent build anything with MVC and if the project has a short time delivery, i will probably find some hinders in MVC that could make me not to deliver the project in Time.

Oscar Cabrero
+1  A: 

I wait for MVC on .net for a long time. I think more than 90% people will choose MVC rather than webform.

sesame
90% is doubtful ... since most ASP.NET developers probably will never know that MVC exists.
Jess
+3  A: 

MVC

... it just seems so obvious that's where the future is

John MacIntyre
+6  A: 

I can't say which I'd really go with having not tried MVC yet. But I'd be a bit worried about using it for a really big enterprise project as yet.

Scroll through pass questions and you'll see that there a lots of questions/issues with MVC (compared to good o' WebForms that is). That alone has me worried. And a lot of the questions seems to be for special UI needs. Again having not tried it I don't know how mature it is yet but I'd still be a bit worried.

Maybe someone who has used it for an enterprise project can shed some light.

fung
+12  A: 

MVC FTW!, Reasons?

  • Total Control over my HTML
  • No Web Forms magic
  • No complex page life-cycles
  • Closer to the metal
  • It is the natural thing to use with HTTP
Khaja Minhajuddin
web-forms magic :D , true true
Omu
+1  A: 

If it was a personal project then I would use MVC. Just to learn more about it. If it was a project at work I would use WebForms, possibly in combination with DynamicData for the administrative parts. The reason is that I would be more productive with a technology I know, and using DynamicData for the administrative part would let me setup that part in minutes.

Rune Grimstad
+1  A: 

As always it depends upon the type of application you are developing and the individual circumstances. A lot of our internal applications are being developed in SharePoint as that is our internal platform of choice for intranet type applications.

This automatically limits us to ASP.Net on the standard model.

I really want to get to grips with MVC, but I don't have a justification for this at work and I have 2 kids and a wife at home so no time to develop at home.

Sometimes circumstances force your hand, if only we all had the choice of exactly what platform, framework etc. to develop with.

Charlie
+1  A: 

I am currently working on a project in Asp.net MVC with jQuery and jQuery-ui, and it's a lot of fun.

If you're familiar with html and javascript (or other MVC frameworks like rails), MVC makes much more sense than the old webforms. And you control the output, not some vague control on a form, so if there is an error on the page or if you want to change the layout you can :).

Morph
+8  A: 

Is MVC the "flavor of the day", or does it have staying power?

I have worked with MVC, and have a vast amount of webform experience. I often wonder about the staying power of MVC.

You should consider this when choosing one or the other. What do you want to support for the entire product lifespan?

pearcewg
+5  A: 

I would choose Webforms for local/intranet applications with rich business logic and MVC for public/internet site (blogs/forums/presentations/simple services). "WebForms application model" is preferable in areas where rich state support is critical

eu-ge-ne
+1  A: 

Hmm.. At the moment I am confused like you are and about to start building a new site :). I was going to start with Webforms, but now I see where the crowd is heading and I think I am going to give MVC a whirl now.

Thanks for asking this question.

Cyril Gupta
"but now I see where the crowd is heading and I think I am going to give MVC a whirl now." -> More or less what I'm thinking. :)
Click Ok
+1  A: 

In ASP.NET MVC you sacrifice your controls toolbox, URL Routing is already in ASP.Net (webforms)

So i would stick with ASP.NET WebForms ( i m not saying that MVC isn't good )

jQuery do you think IT will let you use it ?

Yassir
+1  A: 

Now that it's RTMed and now that there are some very good resources on it I would say ASP.net MVC would be my strong preference, but it's not cut and dried.

Web forms hasn't gone though, it's still there, it's still supported and I've worked on several major sites and used Web Forms very successfully, so if there were other external factors such as a customer preference, or perhaps a team that had solid Web Forms experience then I'd still be happy to work with Web Forms. That said I have already worked on one project with MVC (while it was still in preview), and I much prefer it - my reasons are similar to those given above so I won't repeat them all. I will say that if testability isn't the best reason it's certainly in the top one:).

Steve Haigh
+2  A: 

MVC. We're going to redo an application that is SEO intensive and MVC seams to fit right in out of the box. Plus I want to hang out with the cool kids on the playground.

domus.vita
+5  A: 

I have started a new Web site for our own product a week ago and I couldn't be happier with ASP.NET MVC. Everything seems natural, I always know where to go and look if something doesn't work or does not look the way I intended.

Frankly, the biggest chunk of time I've spent has been CSS. Coding, integration with jQuery... peanuts.

OTOH, if you are not experienced developer, ASP.NET will not appeal to you as it encourages you to go all the way and control all aspects of your site - HTML markup, CSS etc., which in turn means no controls, drag and drop visual editing etc.

Unlike traditional ASP.NET where you are left to yourself and often end up mixing all kinds of UI, persistence (DB) and business logic code in various pages, MVC will guide you and help you structure your app much more consistently. This will not sit with you if you don't like "opinionated" frameworks and/or just want to get the job done without caring about structure of the site, maintainability, scalability etc.

Note that it's perfectly possible not to care about this if all you're building is a one-off intranet site, but for public Internet site I'd choose MVC over classic ASP.NET every time.

rawpower
+5  A: 

While MVC is the new kid on the block there are still a lot of benifits to designing with the Web Forms Model.

  • Familiarity with the tool
  • consistancy of look/feel with exixting projects
  • Tooling/designer
  • postbacks
  • Event driven
  • Controls to abstract
  • 3rd party controls that work
  • Rapid development
  • Declaritive style

Rachel Appel did a great presentation at Mix on this very topic. you can view the video here:
Choosing between ASP.NET Web Forms and MVC
http://videos.visitmix.com/MIX09/T23F

Jim
postbacks are an advantage :D
Omu
A: 

I would like to be doing ASP.Net MVC, even though I'm still very new to MVC. But it's not to be in the foreseeable future.

peacedog
+14  A: 

personally, I have decided to use both...

If its a website (viewed online), I have decided to use asp.net mvc If it was an application (web application with a single purpose) I have decided to use WebForms.

This decision is purely based on the case use and the solution you trying to deliver. If you are interested in good SEO and faster website, mvc is much cleaner HTML and faster than webform.

However If you after a complex functionality with a lot of filters, grids, postbacks on the same page and you are well experienced in winform, just stick with it.

horses for courses... my 2cents

Sarmaad
+1 for acknowledging that MVC and WebForms are not mutually exclusive and, in fact, are perfectly good in creating "hybrid" websites/applications where one can use the functionality of both where needed.
Pretzel
+1 again for specifying the difference! =)
giddy
+2  A: 

I just released a major public site on the MVC platform after using webforms for all previous projects. Without a doubt it is the way to go, IMO.

With webforms, I have found the sites tend to become a mess over time as you have blocks of code in the code-behind that handles both view logic and controller logic. As the site grows and the logic gets more complex it is difficult to trace what is happening and where.

I find that that MVC forces you to break things up in a more logical manner. Controller and model classes allow you to get a better control on the organization of the application. In addition, views are more flexible because there is a specific way of providing data to them, through models.

Also, like others have mentioned, you have more control over the markup and urls and it plays nicer with client libraries like mvc.

The only time I would use MVC is if I was building and intranet site that was focused on reporting data of some sort where the built in controls that come with asp.net would save development time and I wasn't as concerned with the look and feel. I would never use asp.net webforms again for a major public facing site.

Jeff
A: 

i would choose MVC since designers and developers can work in parallel on the same project. Designers can work on the view part (javascript,css, html) while backend developers can work on the controller code.

Joo Park
A: 

I'm actually going to be starting a rebuild of a web site in the next couple of weeks that was horribly written in asp.net 2.0 and I am going to be using asp.net mvc. For a lot of the same reasons as above. I would rather not use custom .net controls and handle the html/javascript (using jQuery) myself. I do a lot of java web development as well so having a good understanding of the underlying html/javascript/css is important to me.

Casey
+2  A: 

Both!

I am making the long haul to MVC. I have too much code that readily works in Web Forms. MVC is fantasic, but it sill leaves a lot in the productivty areas such as templated grids and lists, basic UI controls (calender, autocomplete, etc.) and scafolding. These are all areas where Web Forms excels at, but comes off the rails if you want precise control and want to keep things simple.

MVC 3 and EF Code-Only could be a great marriage if they are willing to bridge the gaps between the two. Most people that use Ruby use it for Rails, and ActiveRecord makes that easy to work with.

Also I would love to see a parallel "Feature Pack" project for MVC with MS support, similar to the way they did the Microsoft Ajax Toolkit, that would say have quarterly updates. I find MVC Futures and MVCContrib both lacking. But I know they only have so much budget. So, here's to hoping that MVC 3 changes all that.

Lynn Eriksen