Biggest advantage to using ASP.Net MVC vs web forms
Asked Answered
A

19

164

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

Among answered 19/9, 2008 at 15:1 Comment(0)
T
165

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.

Thorson answered 19/9, 2008 at 15:1 Comment(5)
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.Prognostication
@ 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'Dialectic
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 ?Hypsography
While these points are mostly accurate for the MVC side, a lot of them are being integrated into WebForms now.Mount
Link to the source of this answer with more details: weblogs.asp.net/shijuvarghese/archive/2008/07/09/…Propolis
H
91

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 • Many controls in ASP.NET web forms automatically generate much of the raw HTML you see when an page is rendered. This can cause headaches for developers. With MVC, it lends itself better towards having complete control with 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.

Homology answered 2/9, 2010 at 17:5 Comment(5)
"With MVC, you have complete control over what is rendered" - you can also have complete control with WebForms if you use Literals instead of Labels, Placeholders instead of Panels, Repeaters instead of Datagrids, etc. Too many developers read statements like this and believe it to be true. Downvote..Alphaalphabet
@Alphaalphabet - I don't know that I personally would downvote, but I agree with the rest of what you said.Altdorfer
@Alphaalphabet - Thanks for saving the StackOverflow world by nitpicking and asking that this question be downvoted. I edited my answer just for you - so hopefully I can get your vote back along with everybody else that you asked to downvote it. Thanks!Homology
@Alphaalphabet I agree partially, but when using literals, placeholders and repeaters, you're moving more and more html to the codebehind. Which can also cause confusion to designers reading the .aspx, and to coders reading the .aspx.cs. So yes it's possible, but yes, it also defeats the purpose of ASP.Net WebForms. I'd say that ControlAdapters are a cleaner solution in that case. Instead of replacing the controls, you replace the way they're rendered.Halfwitted
The statement "With MVC, you have complete control over what is rendered" is confused. I think the better statement would be, "The MVC framework does less rendering and what is rendered is leaner. You're afforded more control over specific HTML/CSS that is rendered, but you have to do the work to get that control."Fixer
D
17

Anyone old enough to remember classic ASP will remember the nightmare of opening a page with code mixed in with html and javascript - even the smallest page was a pain to figure out what the heck it was doing. I could be wrong, and I hope I am, but MVC looks like going back to those bad old days.

When ASP.Net came along it was hailed as the savior, separating code from content and allowing us to have web designers create the html and coders work on the code behind. If we didn't want to use ViewState, we turned it off. If we didn't want to use code behind for some reason, we could place our code inside the html just like classic ASP. If we didn't want to use PostBack we redirected to another page for processing. If we didn't want to use ASP.Net controls we used standard html controls. We could even interrogate the Response object if we didn't want to use ASP.Net runat="server" on our controls.

Now someone in their great wisdom (probably someone who never programmed classic ASP) has decided it's time to go back to the days of mixing code with content and call it "separation of concerns". Sure, you can create cleaner html, but you could with classic ASP. To say "you are not programming correctly if you have too much code inside your view" is like saying "if you wrote well structured and commented code in classic ASP it is far cleaner and better than ASP.NET"

If I wanted to go back to mixing code with content I'd look at developing using PHP which has a far more mature environment for that kind of development. If there are so many problems with ASP.NET then why not fix those issues?

Last but not least the new Razor engine means it is even harder to distinguish between html and code. At least we could look for opening and closing tags i.e. <% and %> in ASP but now the only indication will be the @ symbol.

It might be time to move to PHP and wait another 10 years for someone to separate code from content once again.

Dorr answered 15/2, 2011 at 20:49 Comment(5)
+1 Spot on. My first reaction to MVC was that I was doing Classic ASP all over again; only in C# this time instead of VBScript.Rachelrachele
I'm amazed at why this answer got this many upvotes. Firstly, ASP.NET MVC has the seperation of M-V-C built in. Of course, it is possible for you to do this in ASP. Secondly, ASP.NET MVC is much more than classic ASP. It offers the fine-grained control over HTML combined with the power of .NET accompanied by a lot of useful helpers. Thirdly, @ is a fine notation, as is <% %>. Any decent editor for your Razor views will support the @-notation. Lastly, PHP mature? me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design ASP.NET MVC is a great platform. Give it some more attention.Punctual
Are you kidding me? I've been using PHP with its "<? ... ?>" notation and have found it to be utterly verbose. I don't see how the "@" symbol is harder to recognize than "<% ... %>" tags. Plus you rarely use the "@" symbol in HTML templates.Retortion
My eyes can rest really better on a razor page than on the hell of "<% %>" symbols. Reading an .aspx page gives me headaches. I also prefer to see what is being rendered. A @foreach(..) {<tr>...</tr>} block makes me feel more comfortable than a <abc:MyViewControl ID="..." runat="server" DatasourceID="...." />. I do a lot of client side manipulation and I need to know exactly what is going to be rendered where, and with which id, style and classes. I prefer to do it myself than let a control do it on the fly. Especially when some controls get rendered differently depending on their settings.Lardon
I'm surprised this has upvotes, it's a complete misunderstanding of the MVC framework. If you find yourself mixing code with content in MVC, you're doing it wrong. Your views have content, your controllers (and the classes they use) have code. It's one of the primary principles of MVC.Acerbate
O
14

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.

Odiliaodille answered 23/1, 2009 at 20:41 Comment(3)
"much easier time" using which one?Havildar
@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 learnOdiliaodille
ASP.NET is the base for both WebForms and MVC. People tend to confuse WebForms with ASP.NET. There is no "MVC vs ASP.NET". There is "ASP.NET MVS" vs "ASP.NET WebForms". And actually they are not battling each other. They are just different ways with different pros and cons, to build a websiteLardon
T
13

The problem with MVC is that even for "experts" it eats up a lot of valuable time and requires lot of effort. Businesses are driven by the basic thing "Quick Solution that works" regardless of technology behind it. WebForms is a RAD technology that saves time and money. Anything that requires more time is not acceptable by businesses.

Thoracoplasty answered 2/2, 2011 at 6:52 Comment(3)
+1 for Businesses are driven by the basic thing "Quick Solution that works"Taw
The problem is when some quick solutions just don't work because they intended to be quick in the first place. Recent experience: A quick webforms page to do some basic create-edit-update. It was supposed to be "faster" than the infopath equiveland page which was a little bit slow. Actually the new solution had almost the same performance with infopath page, except in IE7 were it was extremely slower to the point of being useless. 5 seconds to open the page, and 5 seconds each time a combobox was clicked... All of that, just because it had to be quick. No thought, no planning.Lardon
After that, we ended up removing all the controls to get rid of their heavy and unnecessary client-side scripting, and ended up rendering manualy html controls with bootstrapped data and events, and a combination of jQuery and BackBone.js. It is actually an MVC approach hosted in a webforms page. Of course, with good though and planning WebForms and MVC both can perform really well, but WebForms tempts you to just toss controls in your page just to see someting moving on your screen, and then you spend more time tweaking it, if not removing it at all.Lardon
G
11
  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.
Glycerol answered 30/6, 2010 at 1:35 Comment(0)
P
9

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.

Paramilitary answered 19/9, 2008 at 15:19 Comment(1)
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.Hypsography
I
9

I have not seen ANY advantages in MVC over ASP.Net. 10 years ago Microsoft came up with UIP (User Interface Process) as the answer to MVC. It was a flop. We did a large project (4 developers, 2 designers, 1 tester) with UIP back then and it was a sheer nightmare.

Don't just jump in to bandwagon for the sake of Hype. All of the advantages listed above are already available in Asp.Net (With more great tweaks [ New features in Asp.Net 4 ] in Asp.Net 4).

If your development team or a single developer families with Asp.Net just stick to it and make beautiful products quickly to satisfy your clients (who pays for your work hours). MVC will eat up your valuable time and produce the same results as Asp.Net :-)

Identic answered 18/4, 2011 at 3:46 Comment(2)
Disabling viewstate by default while enabling it on the occasional control that actually needs it was a great step forward in ASP.NET 4.Lengthways
Both WebForms and MVC are built on top of ASP.NET.Lardon
P
8

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?

Pious answered 18/8, 2010 at 13:58 Comment(5)
Partial postbacks are an ugly kludgeRaymund
If you have lots of code in your views then you are doing something wrong. Code in views should only concern layout.Raymund
The only reason you would see a page with javascript mixed with css and html is if you were looking at a lazy developer's work who couldn't be bothered seperating styles and scripts. This can happen in web forms AND mvc. I agree the script tags are ugly, but with MVC3 they sure aint no more, and at least you can see what is going on without looking in a code behind file and finding the point where a control is databound...Peepul
Also if you are creating spaghetti code using MVC you are not adhering to the separation of concerns principal and are not using a nice architectural modelPeepul
Using both, I can say that nothing gets messier than WebForms. MVC is clean, except for the server tags, but besides that, all mess is the fault of bad programmers. MVC is designed by core to separate logic from design. Also you mention Telerik. Telerik for ASP.Net AJAX causes such a messy code. Not to mention speed, (stirng) sorting a telerik grid takes: 500ms for 4 pages in ASP.Net WebForms, takes 200ms for 84 pages in MVC. (Tested using their demo's and firebug for chrome.) When it comes to performance and separation, MVC wins definitely.Halfwitted
L
6

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

Luteal answered 22/9, 2008 at 14:30 Comment(2)
Not saying it can't be done with MVC, because I'm sure it has, but if you want to slap together a quick and dirty intranet or extranet app with a lot of bling Telerik and WebForms is hard to beat. Flame away, 'tis the honest truth.Isla
Telerik has MVC controls too (less, and with less options, but nevertheless they have it), and they're A LOT faster than their WebForm variants.Halfwitted
T
5

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)

Trebuchet answered 22/10, 2008 at 10:15 Comment(2)
Do you mean development speed or execution speed?Uranometry
Especially when using telerik with MVC. From their demo's, sorting a grid takes: 500ms for 4 pages (WebForms), 200ms for 84 pages (MVC). What for me a preference of MVC (even though we use WebForms at my company, thought we're considering making the switch) is, is that it's cleaner, you have your views, where you adapt your output, your model, where you mess up the data :P, and your controllers which put it all togetherHalfwitted
N
4

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 ;-)
Nightly answered 10/3, 2009 at 13:54 Comment(0)
B
3

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.

Ballonet answered 25/1, 2009 at 23:14 Comment(2)
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.Odoriferous
@AndreiRinea I think he meant that :P, there's not much use in a non runat="server" form tag when you still want to use webforms, and since you can't/shouldn't nest forms, I think it's kinda obvious what he meant :)Halfwitted
W
2

MVC Controller:

    [HttpGet]
    public ActionResult DetailList(ImportDetailSearchModel model)
    {
        Data.ImportDataAccess ida = new Data.ImportDataAccess();
        List<Data.ImportDetailData> data = ida.GetImportDetails(model.FileId, model.FailuresOnly);

        return PartialView("ImportSummaryDetailPartial", data);
    }

MVC View:

<table class="sortable">
<thead>
    <tr><th>Unique Id</th><th class="left">Error Type</th><th class="left">Field</th><th class="left">Message</th><th class="left">State</th></tr>
</thead>
<tbody>
    @foreach (Data.ImportDetailData detail in Model)
    {
    <tr><th>@detail.UniqueID</th><th class="left">@detail.ErrorType</th><th class="left">@detail.FieldName</th><th class="left">@detail.Message</th><th class="left">@detail.ItemState</th></tr>
    }
</tbody></table>

How hard is that? No ViewState, No BS Page life-cycle...Just pure efficient code.

Walk answered 13/5, 2011 at 20:33 Comment(0)
C
1

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.

Capillarity answered 15/1, 2010 at 4:11 Comment(0)
K
1

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.

Kareem answered 29/3, 2010 at 1:23 Comment(0)
O
0

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.

Odiliaodille answered 25/1, 2009 at 6:29 Comment(0)
I
0

Modern javascript controls as well as JSON requests can be handled much easily using MVC. There we can use a lot of other mechanisms to post data from one action to another action. That's why we prefer MVC over web forms. Also we can build light weight pages.

Ideogram answered 29/8, 2011 at 8:59 Comment(0)
N
0

My personal opinion is that, Biggest dis-advantage to using ASP.Net MVC is that CODE BLOCKS mixed with HTML...
html hell for the developers who maintain it...

Nicolnicola answered 24/9, 2011 at 15:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.