views:

10139

answers:

14

What are some of the advantages of using one over the other?

+14  A: 

MVC is much easier to test
MVC has better separation of responsibilities
MVC is much easier to create very complex websites with a minimum of code

Web forms are very easy to slap together
Web forms hide away complexity from the developer in web controls
Web forms use the same mental model of development that windows forms use

Will
+3  A: 

Biggest single advantage for me would be the clear-cut separation between your Model, View, and Controller layers. It helps promote good design from the start.

Matthew Ruston
I agree this is a major selling point if you have never worked with this type of pattern before, but you can implement your a MVC or MVP pattern in WebForms.Kudos for getting people to move on to a pattern rather than monolithing a webform with datasets, but they arent the type of people I generally hire.
Saint Gerbil
+63  A: 

The main advantages of ASP.net MVC are

1) Enables the full control over the rendered HTML.

2) Provides clean separation of concerns(SoC).

3) Enables Test Driven Development (TDD).

4) Easy integration with JavaScript frameworks.

5) Following the design of stateless nature of the web.

6) RESTful urls that enables SEO.

7) No ViewState and PostBack events

The main advantage of ASP.net Web Form are

1) It provides RAD development

2) Easy development model for developers those coming from winform development.

cvs
Regarding SoC, people can mess up with it just like they use to on webforms, by writing "fat" controllers with lots of business logic or even data access code in it. So I would say SoC is something that must be provided by the coder, the fw can't help.
rodbv
@ rodbv: Very true, but MVC does sort of push you in the right direction, or at least doesn't make you jump through hoops to do so. So maybe that point should read something like 'makes SoC easier to implement'
Erik van Brakel
How does it "Enable Test Driven Development" over any other method ?I'm also confused how it allows RESTful urls when HttpContext.RewritePath Method (String) has been around since .NET 2.0 ?
Saint Gerbil
+3  A: 

Web forms also gain from greater maturity and support from third party control providers like Telerik.

Timbo
+2  A: 

In webforms you could also render almost whole html by hand, except few tags like viewstate, eventvalidation and similar, which can be removed with PageAdapters. Nobody force you to use GridView or some other server side control that has bad html rendering output.

I would say that biggest advantage of MVC is SPEED!

Next is forced separation of concern. But it doesn't forbid you to put whole BL and DAL logic inside Controller/Action! It's just separation of view, which can be done also in webforms (MVP pattern for example). A lot of things that people mentions for mvc can be done in webforms, but with some additional effort.
Main difference is that request comes to controller, not view, and those two layers are separated, not connected via partial class like in webforms (aspx + code behind)

Hrvoje
Do you mean development speed or execution speed?
Jules
Obviously execution speed.
Andrei Rinea
+3  A: 

If you're working with other developers, such as PHP or JSP (and i'm guessing rails) - you're going to have a much easier time converting or collaborating on pages because you wont have all those 'nasty' ASP.NET events and controls everywhere.

Simon_Weaver
Excellent point!!
Andrei Rinea
"much easier time" using which one?
Cawas
@cawas - much easier with MVC. there are no events in ASP.NET MVC. basically you're dealing with standard HTML and css and not a lot of events and controls that PHP/JSP developers would need to learn
Simon_Weaver
cool, thanks! very good to know.
Cawas
A: 

You don't feel bad about using 'non post-back controls' anymore - and figuring how to smush them into a traditional asp.net environment.

This means that modern (free to use) javascript controls such this or this or this can all be used without that trying to fit a round peg in a square hole feel.

Simon_Weaver
+2  A: 

MVC lets you have more than one form on a page, A small feature I know but it is handy!

Also the MVC pattern I feel make the code easier to maintain, esp. when you revisiting it after a few months.

Almond
ASP.NET Webforms lets you have as many forms on a page as you want. The limitation is that only one can have "runat="server" attribute.
Andrei Rinea
A: 

My 2 cents:

  • ASP.net forms is great for Rapid application Development and adding business value quickly. I still use it for most intranet applications.
  • MVC is great for Search Engine Optimization as you control the URL and the HTML to a greater extent
  • MVC generally produces a much leaner page - no viewstate and cleaner HTML = quick loading times
  • MVC easy to cache portions of the page. -MVC is fun to write :- personal opinion ;-)
Nicholas
+1  A: 

I can see the only two advantages for smaller sites being: 6) RESTful urls that enables SEO. 7) No ViewState and PostBack events (and greater performance in general)

Testing for small sites is not an issue, neither are the design advantages when a site is coded properly anyway, MVC in many ways obfuscates and makes changes harder to make. I'm still deciding whether these advantages are worth it.

I can clearly see the advantage of MVC in larger multi-developer sites.

Rod Rye
A: 

Main benefit i find is it forces the project into a more testable strcuture. This can pretty easily be done with webforms as well (MVP pattern), but requires the developer to have an understanding of this, many dont.

Webforms and MVC are both viable tools, both excel in different areas.

I personally use web forms as we primarily develop B2B/ LOB apps. But we always do it with an MVP pattern with wich we can achieve 95+% code coverage for our unit tests. This also alows us to automate testing on properties of webcontrols property value is exposed through the view eg

bool IMyView.IsAdminSectionVisible{
       get{return pnlAdmin.Visible;}
       get{pnlAdmin.Visible=value;}
    }

) I dont think this level of testing is as easily achived in MVC, without poluting my model.

En
+2  A: 
  1. Proper AJAX, e.g. JSONResults no partial page postback nonsense.
  2. no viewstate +1
  3. No renaming of the HTML IDs.
  4. Clean HTML = no bloat and having a decent shot at rendering XHTML or standards compliant pages.
  5. No more generated AXD javascript.
Francis Shanahan
+1  A: 

Francis Shanahan,

  1. Why do you call partial postback as "nonsense"? This is the core feature of Ajax and has been utilized very well in Atlas framework and wonderful third party controls like Telerik

  2. I agree to your point regarding the viewstate. But if developers are careful to disable viewstate, this can greatly reduce the size of the HTML which is rendered thus the page becomes light weight.

  3. Only HTML Server controls are renamed in ASP.NET Web Form model and not pure html controls. Whatever it may be, why are you so worried if the renaming is done? I know you want to deal with lot of javascript events on the client side but if you design your web pages smartly, you can definitely get all the id's you want

  4. Even ASP.NET Web Forms meets XHTML Standards and I don't see any bloating. This is not a justification of why we need an MVC pattern

  5. Again, why are you bothered with AXD Javascript? Why does it hurts you? This is not a valid justification again

So far, i am a fan of developing applications using classic ASP.NET Web forms. For eg: If you want to bind a dropdownlist or a gridview, you need a maximum of 30 minutes and not more than 20 lines of code (minimal of course). But in case of MVC, talk to the developers how pain it is.

The biggest downside of MVC is we are going back to the days of ASP. Remember the spaghetti code of mixing up Server code and HTML??? Oh my god, try to read an MVC aspx page mixed with javascript, HTML, JQuery, CSS, Server tags and what not....Any body can answer this question?

Ganesh
Partial postbacks are an ugly kludge
UpTheCreek
If you have lots of code in your views then you are doing something wrong. Code in views should only concern layout.
UpTheCreek
+6  A: 

ASP.NET Web Forms and MVC are two web frameworks developed by Microsoft - they are both good choices. Neither of the web frameworks are to be replaced by the other nor are there plans to have them 'merged' into a single framework. Continued support and development are done in parallel by Microsoft and neither will be 'going away'.

Each of these web frameworks offers advantages/disadvantages - some of which need to be considered when developing a web application. A web application can be developed using either technology - it might make development for a particular application easier selecting one technology versus the other and vice versa.

ASP.NET Web Forms:

  • Development supports state • Gives the illusion that a web application is aware of what the user has been doing, similar to Windows applications. I.e. Makes 'wizard' functionality a little bit easier to implement. Web forms does a great job at hiding a lot of that complexity from the developer.
  • Rapid Application Development (RAD) • The ability to just 'jump in' and start delivering web forms. This is disputed by some of the MVC community, but pushed by Microsoft. In the end, it comes down to the level of expertise of the developer and what they are comfortable with. The web forms model probably has less of a learning curve to less experienced developers.
  • Larger control toolbox • ASP.NET Web Forms offers a much greater and more robust toolbox (web controls) whereas MVC offers a more primitive control set relying more on rich client-side controls via jQuery (Javascript).
  • Mature • It's been around since 2002 and there is an abundance of information with regards to questions, problems, etc. Offers more third-party control - need to consider your existing toolkits.

ASP.NET MVC:

  • Separation of concerns (SoC) • From a technical standpoint, the organization of code within MVC is very clean, organized and granular, making it easier (hopefully) for a web application to scale in terms of functionality. Promotes great design from a development standpoint.
  • Easier integration with client side tools (rich user interface tools) • More than ever, web applications are increasingly becoming as rich as the applications you see on your desktops. With MVC, it gives you the ability to integrate with such toolkits (such as jQuery) with greater ease and more seamless than in Web Forms.
  • Search Engine Optimization (SEO) Friendly / Stateless • URL's are more friendly to search engines (i.e. mywebapplication.com/users/ 1 - retrieve user with an ID of 1 vs mywebapplication/users/getuser.aspx (id passed in session)). Similarly, since MVC is stateless, this removes the headache of users who spawn multiple web browsers from the same window (session collisions). Along those same lines, MVC adheres to the stateless web protocol rather than 'battling' against it.
  • Works well with developers who need high degree of control • ASP.NET web forms automatically generates much of the raw HTML you see when an page is rendered. This can cause headaches for developers. With MVC, you have complete control over what is rendered and there are no surprises. Even more important, is that the HTML forms typically are much smaller than the Web forms which can equate to a performance boost - something to seriously consider.
  • Test Driven Development (TDD) • With MVC, you can more easily create tests for the web side of things. An additional layer of testing will provide yet another layer of defense against unexpected behavior.

Authentication, authorization, configuration, compilation and deployment are all features that are shared between the two web frameworks.

Jeremiah