Is MVC the best way to code asp.net applications? [closed] - asp.net-mvc

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
update: I know there is no one best way to do everything. Sorry for not saying that right off. In the context of the data-access tutorials, if you had to do the project he did in that tutorial, would you do what he did or would use use MVC, if you had to choose one of them?
Update: Is MVC the more appropriate way to program asp.net applications, instead of the tutorials found here:
http://www.asp.net/Learn/data-access/
Original:
I ask, because I initially learned about MVC with Java applications, then things like RoR, and Django. These other projects and companies spoke as if MVC had been around for a very long time, and from what I found out it had. Then Microsoft started putting MVC into the .net framework.
I ask because I don't know how to design things very well and thought I was doing well to emulate what's on the asp.net site with Scott Mitchell's tutorial. I thought that creating abstract layers in a BLL was the way to go until I found out about MVC and now asp.net's MVC.
I honestly don't know what the "right" way is to do things. I just create what I need, but I can't help feel like I am missing something.
Is MVC the correct way to start doing things in large projects, specifically I mean MVC and ASP.NET, but could just as well mean PHP and one of their MVC frameworks.
I'd like to settle on a standard way of doing things...for now anyway.
And, out of curiosity, why did Microsoft only now start doing MVC?
UPDATE: Is MVC better than the current tutorial set on asp.net?
I'm referring to the Scott Mitchell tutorials where he creates the BLL for abstraction. Or is that a linq question as well. I should have said that I understand the need for keeping logic and presentation separate but unsure the best way to do it. I was using the asp.net tutorials. It worked fine. Then I found out the rest of the world, as I saw it anyway, was using MVC. Then Microsoft started developing MVC, so to me the other method seems obsolete and the wrong way to do things.

No, it's not the only best way to do things.
MVC is just a design pattern. The goal of all design patterns is simplicity. So as long as it makes your design simpler, go with it. If it makes things more complex for your specific application, try a different approach.
Unfortunately, some people think if they see a pattern, they should use it. It's just not true. Design patterns don't inherently make your application better. They are not an end. They are a means to an end (which is simplicity). So you should use them only if they are worth it.
In my opinion, over-architecting things without a good reason is worse than writing code without any specific design.
EDIT: Regarding ASP.NET MVC: I have a negative personal bias toward ASP.NET Web forms. Before MVC, I did most of the dynamic aspects of advanced projects by writing custom handlers to have fine grained control over the HTML. Web Forms make Web development very easy but they have particularly a couple things that are good but sometimes are problematic. The first of which is ViewState and the second is complex WebControl architecture. Don't get me wrong. Those are signs of brilliance of ASP.NET. I haven't seen a single platform for Web development as easy as ASP.NET Web Forms and this is only because of great WebControl support which requires ViewState. However, in some projects, you want to have precise control on rendered HTML (specially when you have some client-side logic). You also want to make server side code maintainable in large projects. In those areas, ASP.NET MVC really shines. But I think ASP.NET Web Forms will remain a great technology where it's more applicable. After all, as I said regarding design patterns in general, you should carefully evaluate your design to see which one better fits your needs.
Specifically, about data access, MVC usually requires more code than Web Forms counterparts. For presenting tabular data (i.e where GridView is applicable), I think ASP.NET Web Forms is the easier way to accomplish things. However, most data driven Web apps are not just manipulating a table directly in a database. They have complex layout. StackOverflow is a great example of this. It is certainly data driven, but ASP.NET MVC better suits it.

There is no "right" way to do things without knowing what "things" are. MVC is a design pattern that solves a specific common problem - separation of presentational and domain logic. Every design pattern is a commonly accepted "good" solution to a specific problem.
Those solutions, combined with knowledge and experience are building blocks for a good design. The "right" way to do things is to study your problem domain, research on possible solutions and apply the set of solutions that work best to solve it. Making mistakes is a part of the process as well, so don't be afraid to experiment and then refactor with rigor until you reach the solution that serves you best.

MVC is the worst way to develop applications, except for all other ways that have been tried. :-)
Joking aside, MVC is one application design that encourages us not to write spaghetti code. It's a guideline that reminds us to keep business code separate from presentation code. This is very helpful as the application gets more complex.
There are other variations that achieve that same benefit, but are not strictly the same as MVC. Presentation-abstraction-control (PAC) is one example.
As for why Microsoft is so late in adopting MVC, I'm not surprised that they are. They are pretty well-known (at least in recent years) for being conservative instead of innovative. They prefer to let other smaller companies take the risks in an unproven market, then they learn from the mistakes, churn out an overengineered competitor solution, and dominate through marketing.
Example: Microsoft Internet Explorer was considered to be a latecomer to the browser market. Netscape had become very popular, leading the way in providing a platform for people to view HTML. Once the amount of HTML content on the Internet was at a useful level, Microsoft belched up their onomatopoeic "IE" product and quickly captured an overwhelming market share.

MVC is just one way of doing things. I like it because it helps to promote extensibility and is structured to allow testing and code reuse. There is no silver bullet, one true way to do everything but I use it quite often.
In regard to Microsoft, I would say that they adopted the pattern as an alternative to WebForms development for the reasons I mentioned above. I would recommend looking at Rob Conery's MVC Storefront and kind of play around with the examples to see how it works for you.

There is no "best" way to code things. It depends on the application in question; sometimes MVC is the right choice, and sometimes it's not. A good developer is able to weigh his/her options and choose the one that's best suited for a task at hand, instead of just going with the method du jour

If MVC solves the Primary Technical Imperative of managing complexity in your application then it may be a good solution, but it is by no means the only solution.

MVC is one of any number of design patterns. Whether it's the best technologically, or the simplest, or for what types of projects it's appropriate, are are all arguable (see other SO threads). In any case, few would argue against the prevailing consensus that for most cases, it's "Good Enough".
But it has the undeniable benefit that a lot of people use it, on a lot of different platforms.
So if you want to use a methodology that is likely to be around a while; or you don't want to depend on one vendor for support and extension and refinement; or you work in a group that would like to grow by hiring people from various backgrounds who will grok a shared methodology quickly; or you would like to maximize your opportunities to move on if you need to, then MVC is one of the very best ways to support those goals.

MVC being "Better" or "Worse" pattern is relative to the project.

Related

Is MVC easy for a Classic ASP guy to learn [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I've pretty much worked with Classic ASP for ever since it was released almost.. But i am having trouble adapting to the ASP.NET platform.
I have been suggested by many to move to PHP, since it's spaghetti code (I LIKE SPAGHETTI CODE), and it's just like classic asp.. But learning Apache servers and securing them i heard was another big project to learn by yourself.. And since i know more about MS servers, i prefer to stay with MS.
But, I really want to learn another platform, and i was looking at MVC framework and that MVC 1, 2 or 3 is like spaghetti code? Maybe i'm wrong. I assume MVC3 is the best now?
Anyway, From Classic ASP, which would be the easiest and most difficult to grasp you think? ASP.NET with all the compiling and using visual studio, reminds me of when i used to make apps in Visual Basic, but i really like spaghetti code more than compiling stuff..
If there is anyone who has done this switch over from classic asp before, what did you do and why, how easy was it to grasp the new platform? (Preferrably MVC)
Well, MVC is more like classic asp than webforms is. However, it uses structure and frameworks to reduce spaghetti code and make it more maintainable. You have to apply a lot of new concepts to not fight the framework.
For example, a strong seperation of view, model, and controller. This is not something you would do in classic asp, or even generic php (you can do mvc in php, but it requires more discipline and using frameworks as well).
Bottom line is, spaghetti will always bite you in the long run.
Asp.net supports a mode where you don't have to compile anything, you just edit the files on the server and it compiles them at runtime automatically. This is the so called "Web site" model. However, MVC does not work that way and requires the "Web application" model that does compiling (although you only have to compile code, not markup).
I'm currently smack in the middle of my first large ASP.NET MVC project after (and while still) programming in classic ASP for years. I have also programmed in ColdFusion and I have tried Python as an alternative to ASP.NET MVC.
If you want to stick to Microsoft technology MVC is the closest you will come to classic ASP. Webforms is really Microsofts way to make web-applications similar to application development. Microsoft has tried to abstract away the fact that the web is a stateless medium. However, this results in pretty ugly things such as the viewstate (a hidden form field that tries to keep the state of all form fields) and controls that generate HTML over which you have absolutely no control.
MVC gives you more control, and leaves you to handle the statelessness like classic ASP does.
I have still found there is a steep learning curve though; you will have to learn a lot of new things, if all you ever did was program vbscript/ASP:
C# or VB.Net Syntax
Object oriented programming in general (inheritance, dynamic versus static, etc.)
Concepts such as lambda expressions, delegates etc.
The MVC pattern
Most likely also a data-access technology like LINQ or Entity Framework
I'm still struggling with some of these, but I'm getting there. It does take a lot of work though, and perseverance. Not everything is better or easier than in classic ASP. Especially for me, as I have been using WSC's in classic ASP for years, which enables n-tier applications in classic ASP, and eliminates spaghetti code completely.
As I mentioned, I also looked into Python as an alternative; Although at the company I work for we now switched to ASP.NET MVC, I actually found the transition to Python a lot easier. The only reason we went with MVC is the fact that it seemed easier to get new developers when using C#/MVC. (In retrospect this wasn't actually true, we are having an incredible hard time finding a suitable C# programmer around where we are located)
Mind you, in Python you will still have to learn basic Object Oriented programming, but the implementation is much simpler to use than .NETs and the Python language is (IMHO) more like vbscript than VB.NET is.
Also I liked the fact that I don't have to define the type of every variable/function/parameter. This sometimes drives me crazy in C#; if the type of a function changes, it could affect a lot of other functions and variables, which all have to be changed. Also, the syntax is easier to pick up because the language is simple and there aren't a hundred ways to do the same thing.
You can choose between different frameworks, MVC or non-MVC and you can use Python in a lot of other fields as well (application programming, scripting-for example XBMC).
There are also ORM solutions available like Entity Framework for .NET and I found the one I looked into (SQLalchemy) a lot more powerful, and easier to pick up than EF.
So at work I'm currently learning ASP.NET MVC, at home I'm slowly picking up Python. I suggest you try a very simple project in different technologies, and pick the one you find easiest to get started with.
Hope this helps.
If you like your spaghetti served by Microsoft, try any Windows version that supports IIS7. PHP works perfectly and it's really easy to setup with Web Platform Installer.
With that in mind, there is no real reason you should choose any one web technology over the other. You can mix and match as needed, even within a single app.
If you want to get into MVC, forget about 1 and 2 and go straight to 3. MVC is much closer to the metal than ASP.NET WebForms. With your background in classic ASP, you'll probably like it once you get the hang of it.
Update:
If you're serious about learning either MVC, PHP, Ruby or whatever web platform you like. Get a good book. Sit down, read it and follow along with the sample code. I usually decide what book to buy based on the reviews at amazon.
Then, if you need more info on specific topics, go read authorative blogs on the subject. For ASP.NET MVC you'll probably want to look at blogs from Brad Wilsons and Phil Haack.
I started using Classic ASP back in the days but then moved to WebForms now using/learning MVC 4.
Here are my thoughts.
For me Classic ASP was fun and easy to learn as it was simple and did not have a large learning curve, data CRUDS were not difficult either and it did the job in a fairly efficient but messy manner.
WebForms required a higher learning curve but helped with a lot of 'plumbing' code with drag and drop controls, however these were sometimes difficult to modify and customise.
With MVC I have found it requires a larger learning curve than the other two, this is mainly due to it being driven by HTML5 and client frameworks like Knockout etc. To gain a good understanding also requires one to learn OO patterns, Entity Framework, LINQ, WebApi and initially these I did not find simple to digest.
What is easy for you? What part do you find difficult? Read up about a stateless nature of HTTP and find comparisons between web forms and MVC - this should make few things clear.
Do some reading about MVC pattern in general. MVC is a general term which appeared first time over 30 years ago. MVC in .NET 4 is a variation of this pattern, but we are all used to calling it MVC. Make sure you OO knowledge is up to scratch, as well as knowledge of basic design patterns, mainly SoC (Seperation of Concerns) and SRP (Single Responsibility Principle).
if you want to learn / start with the mvc framework I could recommend you do the Contoso University tutorial or the NerdDinner one ( http://www.asp.net/mvc/tutorials#NerdDinner )

MVC Getting Management approval

I have just started looking into .net MVC and I really like it.
There are a few developers within our team who think the same. But before we are allowed to use it for any project we need to get the approval of management.
What would be the best way to convince management(which know little about programming) that this would worth while and it could have some cost benefit?
My belief is that it will force us to write better more accessible sites which are a lot more testable than web forms. Which in return would mean less bugs and higher customer satisfaction. But I have no evidence of this.
EDIT:
We have a team meeting in 4 days, this is where I will be making my pitch to the team and management.That gives me two weeks to learn more on MVC and do a presentation.
Ok, I'm a manager. I've been one for more than 10 years. Luckily, I've been able to stay very current with my technology passions, so I think I can speak from both sides of the fence.
Managers are going to be concerned with three things here: risk, cost, and the status quo. So, when you present your plan, you're going to need to address each of these:
Risk:
Explain to them that the risk here is very low.
MVC2 is just an extension of MVC, both of which has full source code available (management speak: if we find a problem, we don't need support. We can fix it ourselves).
There's a ton of community support. (management speak: I can go online and get answers to any questions I have in a matter of minutes).
Heavy-hitters at Microsoft are pushing this (management speak: Microsoft is encouraging their developers to use this technology).
Cost
Talk about the fact that the technology is free, with a ton of community support.
Be ready to talk about ramp-up costs for any developers that don't have MVC experience. They're going to be less productive at first. Let your manager know that the developers will come up to speed quickly, and that MVC provides more efficient coding approach than traditional web forms.
Be ready to talk about costs and risks associated with ongoing maintenance. If you've already got a ton of web forms out in the wild, this will present a second skillset that developers will need to maintain. Find ways to convince management that it will be possible to maintain this skillset.
Status Quo
Many people become managers because they want a level of security and control in their life. If this is the case with your manager, they'll be interested in maintaining a comfortable status quo, and not making significant changes. If that's true here, you need to make the case that this really isn't a major change from what's being done today. Assure them that you have a back-out strategy. Talk about how this is really a proof-of-concept for MVC use in your organization, and that management will have an opportunity to review the success of the project prior to you ever suggesting MVC become a standard.
Really what it comes down to is the fact that ASP.NET MVC forces developers to write better, more scalable, and easier to test code. It moves them away from the crapshoot that webforms often can be, and in a direction oriented toward quality architecture and good clean code that follows more rigid conventions.
One definite drawback of MVC is that the View structure required by the webforms view engine (default) encourages you to write spaghetti code in the views that is, at times, a nightmare to maintain. Given this fact, you might even want to pitch them with the new Razor View Engine that was recently announced. With it you can write some extremely clean view code that even the non-developers at your company could manipulate without bringing mass death and destruction to your application. Compared to the markup in the webforms view engine, Razor's markup is pretty much beautiful.
Also, check out this really solid blog post by my buddy Matt Hidinger which does a great job of breaking down why MVC is so awesome.
When you speak to management just be sure to emphasize the all good points mentioned so far, and then compare them to all the bad that webforms is/can be. Be practical and realistic; if you have enough people on your team that are ready to jump on board with MVC then it's pretty much the best possible decision you can make, in my opinion, anyway. You may even want to take a moment to show them some of the great sites that use it- like Stack Overflow.
Personally, I have launched about 15 separate sites built with ASP.NET MVC and as such I feel I have a pretty solid understanding of it. I can wholeheartedly tell you, from my experience, MVC is the best thing that ever happened to ASP.NET.
It really depends on what you're comparing it to, but assuming it's an alternative to webforms, a few items to mention:
better testability
more control over output, which can help target other devices
leverage existing knowledge of .net
MVC framework encourages you to write more structured, testable and, as a result, more maintainable code. As the biggest costs in development are in the debugging and maintenance, those benefits alone should be a good validation. That said, it's still possible to code crap in MVC and that shouldn't be overlooked. If your company has a lot of expertise in another development framework then you really need to address the deficiencies in that and how MVC can rectify those deficiencies.
I would start by looking up blog sites that support MVC and compiling some of the advantageous features of MVC. I would start with Scott Guthrie's initial blog post regarding MVC - it outlines some great features - http://weblogs.asp.net/scottgu/archive/2007/10/14/asp-net-mvc-framework.aspx
If you are looking at trying to bring MVC in and need to convince management of the value, your best approach is too show how it can reduce long term support costs. Having an application that has well developed unit tests with decent code coverage can ensure quality over the life cycle of the application because you can higher level of confidence that changes you introduce have not broken pieces of the application. This doesn't negate the need to test the application, but you will find breaking changes faster. An approach utilizing MVC over MVC is a much more flexible platform for this testing.
There are many studies you can utilize that show the long terms support/maintenance costs of an application are often greater than the initial development costs. Stephen McConnell's Code First has a good discussion of this.
Good luck!
As opposed to what? Management would rather you wrote poorly-designed code? I'm surprised it's even an issue, in that whatever else they're asking you to do, by the current state of the industry, is self-evidently the wrong decision. If they know what MVC is, I can't see how any reasonable person would want you not to use it.
Sell it as an ASP.NET component, only made by Microsoft to incorporate some of the newer web 2.0 technologies moving forward. Tell them it will enhance maintainability while reducing development time. Tell them it uses existing infrastructure, and is more performant. Tell them it uses existing investments in training and software. Tell them it is more efficient, and makes it easier to fix issues and build enhancements. Tell them they'll get more out of their development team without allocating more resources.

ASP.Net MVC issues, meant for advanced developers only?

Just a random question. I've been in internship and then working as a software designer for almost a year now, mainly with SQL Server 2005 / 2008, and Visual Studio 2008 with ASP.Net VB / C#, web software development. We recently started a project with ASP.Net MVC, and I just don't get this stuff.
The concept of Views, Controllers, Models etc is clear. I'm still a bit confused with some of the syntax, but it doesn't seem impossible to get. My problem however, is with all the basic controls and functions you had with basic ASP.Net. Want a dropdownlist? Go browse through 15 tutorials one of which may actually work. How about a gridview with editable rows? Manually build the tables or helper classes with loads and loads of code also built from several different tutorials. What about panels or multiview indexes to easily control the visible user-interface on a page? Well, go learn another tutorial about how to do it all from scratch. Etc..
I do not argue the idea that MVC is worth it. It has to be, with so many people smarter and more experienced than I am saying so. But I've now fought with this beast for over a month and am getting increasingly frustrated at having to use hours to days of time to do the most basic tasks that were easy even when I was barely beginning with the whole programming thing almost a year ago.
So my question. Are there others out there like me? Are there perhaps nice blogs or articles opening all this up to people like myself? Is ASP.Net MVC just something that is so hardcore advanced that you NEED to have extensive experience and talent to actually master it?
Thanks for your time.
It's not for advanced developers. It is for good developers.
Most ASP.NET WebForms developers have made it somehow through years without having a slightest idea of HTML, CSS, JavaScript or HTTP. Drag and drop some control, set up some properties and here you go. It is not the way of a professional. You need to know the basics. It is only a matter of time until some situation arrives where a standard control cannot help and you need to work around the postback mechanism, viewstate etc.
I agree that it is definitely more work trying to implement an editable data grid, add persistance for controls, add some nice Ajax effects instead of relying on UpdatePanels, yes. But you really need to know this stuff if you wish to be working as web developer.
What you are experiencing is being overwhelmed at once by all those things you should have learned already but have managed to postpone thanks to very well done abstraction mechanism of WebForms. The best course of action is to start learning these things now, step by step. It will likely take you at least 6 months of intensive studies to feel more or less confident with doing stuff manually. But when you have done this, you will be looking back at your start and feeling glad you did it.
I was trying to work out what the problem was with MVC until I grasped the essential difference between the person asking the question and me - it would be this, I first laid hands to keyboard in 1979 whereas Zan has been "working as a software designer for almost a year now".
When I started one more or less had to do everything (at least in terms of presenting a UI) from scratch - or at least using far more limited toolkits than is the case today. The notion of constructing a drop down list by running a loop to create the options is in some respects considerably less alien to me than binding a datasource to a control and having the result appear as if by magic (notwithstanding 9 years of VB.OLD and over 6 years of .NET and C#)
And that is the core difference between Forms and MVC as it currently stands - the way you produce the presentation code and consequently the fact that you need to understand HTML and do seemingly more work to achieve similar results (and this is one of the reasons that people keep emphasising, quite rightly, that MVC is NOT an appropriate solution for every project). In terms of the structure of an application - MVC encourages a better (more testable) style but its not the only means to achieve that end - the majority of the techniques are as applicable using forms and alternative patterns.
And again this raises the challenge of contemporary frameworks and tools - they do a huge amount of work for you (go look at Dynamic Data for example) but they also hide so much from you that we lose track of the fundamentals and of an understanding of the basic building blocks from which our complex applications are constructed. In this case the problem sounds like one I've had which is learning about the nuts and bolts how a web page is actually constructed (HTML, CSS, Javascript) and how it interacts with the server as opposed to just having the whole client experience automagically generated for you.
MVC is no more a tool for "good developers" than Forms is - rather its a good tool for developers that wish to achieve a particular result albeit one that comes with a price just as forms is also a good tool but with different outcomes because you're accepting a different set of compromises.
A good developer is one that can adapt - can learn the new techniques necessary to work on a different platform, to target new environments, to use appropriate solutions for a particular task and ultimately that can apply solid patterns and methodologies to their work in so far as is possible whatever the dev environment...
i also spend one year on mvc what i learn till now is u can rely on client side as much as u can but in classic asp.net most of time u used server side controls like gridview. In asp.net mvc u can replace it with jquery controls like jQgrid and jquery datatable. you must have to spend some time to learn asp.net mvc the it might looks u better then asp.net classic.
for reference read asp.net mvc pro book
MVC is not a new concept; in fact other languages have this kind of framework long before Microsoft got it. Think about Ruby On Rails, Zend Framework, Symfony etc.
If you say that MVC is for the hardcore and the alpha geeks, then by your logic other language developers are much more advanced than .Net developers. I don't think this is true.
Your problem with MVC stems from your webform background; ASP.Net and ASP.NET MVC greatly differ in terms of concepts and approach. So some unfamiliarity is expected for those who are moving from one framework into another. Me, on the other hand, who has no webform experience ( although I do have winform experience), don't find MVC hard to grasp.
And I don't think I am smarter than anyone else.
All i can suggest is that you need to do more of it! The more you practise, the more it will become clear. That's how it was for me. I was fundamentally stumped by the MVC concept to start with but after much frustration i just decided i would need to force myself to start using it or i'd never get it.
I'd recommend actually completing one or two of the tutorials found on the asp.net/mvc site from start to finish. I can personally recommend the NerdDinner (and the book from which this example was birthed - Pro ASP.NET MVC 1.0) and Storefront tutorials.
ASP.NET MVC is built on top of bunch of old concepts - HTTP, HTML, CSS, JavaScript. And so on. The whole point is to bring their power directly to your hands. If you can't handle this power - for example, you're not familiar with HTTP statelesness, or how to build rich pages with HTML/CSS/JS - you can't do much with ASP.NET MVC.
If you say that you're in programming for only one year then you're most probably not familiar with those concepts and that's the problem, not in the MVC itself.
Maybe you take ASP.NET MVC as a refinement of ASP.NET. That's wrong. They're VERY different. Imagine yourself doing web development with only HTML, CSS, and jQuery [1]... can you? If you can't then you will have troubles doing MVC.
I personally worked with ASP.NET for couple of years, and ASP.NET MVC was a breath of fresh air. It's just so much simpler and cleaner.
[1] This can be done, for example with data fed via web services.
MVC is great but the argument that it makes you happy by finally giving you the power of HTML, CSS and Javascript is real crap. The same logic would say: code in pure SQL and forget nHibernate or Linq. Why is abstraction bad? I like MVC but please don't use such arguments. MVC needs something to be able to build complex rich user interfaces (which are browser compatible).
Finally, on HTML, CSS and Javascript. The fact that MVC forces you to go back to the basics does in now way mean that the developers do it right. Whether you use web forms or MVC, a bad JS developer stays a bad JS developer (and same for HTML or CSS).
Sometimes it is better to not give too much power to the weaker developers in a team.

MVC versus WebForms [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
It seems to me like there's a lot of sheeping going on, with everyone jumping on the MVC bandwagon.
Almost everyone is declaring WebForms as evil and satan without much persuasion. Then they go on to say that Controls are evil and they shouldn't be in a Web app. How are you going to show anything without any controls?
I remember when WebForms first came out and everybody loved them. I guess in a few years, people will sheep on to the next thing and declare MVC evil because you had to actually create controls to use MVC and they'll say you have to develop an application and not worry about the controls.
The way I see it MVC can be achieved in WebForms by not including the RunAt in the Form tag.
Then if you want to retrieve data, just use Ajax.
Can someone persuade me on why I should use MVC and not WebForms?
You shouldn't arbitrarily decide between one or the other; don't plump for the MVC framework just because it's the new kid on the block and everyone's singing its praises, especially not if you're comfortable with doing things using Web Forms. Practically every existing system is going to be using the older, more established technology, and there's nothing wrong with that.
While it's true that the MVC framework does allow for even easier separation of concerns (after all, that's what the MVC pattern is for), it also brings with it the responsibility of writing more HTML, and I think a slightly greater understanding of how the web works; not necessarily an unreasonable requirement, but you could argue it'll slightly slow you down the first few times you set about using it.
To be honest, I agree that Web Forms takes a lot of undeserved flack. Granted, there's a lot of magic going on in the background, and you get less control over some of the HTML output, but it's not exactly impossible to style with CSS (you end up using !important a lot, perhaps), and it's also not impossible to get some separation of concerns, even if it doesn't meet the purist's view of what that might be. You can still write pretty horrible code using the MVC framework. If you're looking to throw together something quickly, and you're good with Web Forms, then you're going to be able to achieve that very quickly, and it's nothing to be ashamed of, is it?
That's not to say, of course, that you should stick to your guns and ignore MVC either; it's a good framework (in fact, it's a very good framework) and it does confer several benefits which you might want to take advantage of in the long run. You also have to remember that it doesn't automatically nullify everything you learned about ASP.NET 2.0, either; a lot of the supporting architecture is embraced in the MVC framework, including things like the membership providers.
In Webforms:
Both Viewstate and Postbacks have been made lot of problems and increased complexity of the web application development. Many web pages having hundreds of KB size of Viewstate that affected the performance of the applications sometime.
Developers do not have the control of the rendering HTML of web forms and Server controls that render html with mixed inline style and deprecated tags that does not follows standards.
The page life cycle of the Web Form is too complex and has the tightly coupling between all things in the ASP.net framework and a single class is used both to display output and handles user input.
Unit testing is almost an impossible task. Today unit testing is very important in modern software development especially when we following agile methodologies and practices. Since web is a stateless thing, Events, Postbacks and Viewstate are not a good way.
With asp.net MVC all these things are simplified
If these things don't apply to you and you enjoy using Webforms then stick with what you do best. Don't try to fix something thats not broken.
For more detail refer to : Shiju's blog of ASP.net MVC Vs ASP.net Web Form
I see the key advantages of MVC as:
Much cleaner and simpler architecture. No more guessing which event you have handle to hook up your data correctly. No more having to insert a hook to "fix" a data binding problem because the framework doesn't do exactly what you want.
The framework doesn't get your way as much.
Decoupled architecture makes much more of the code more easily tested.
More closely aligned with the architecture of the web. For people coming from a WebForms background this may not seem to be an advantage until you embrace it and design for it instead of trying to write WebForms-like applications in MVC. Fortunately, I had explored Ruby on Rails some before using ASP.NET MVC and had already started to write my WebForms apps in a more RESTful way.
History/Ubiquity -- despite the fact that Microsoft is just rolling it out, MVC is a well-known and highly respected pattern. It's widely used for lots of web applications in many frameworks. Learning MVC will give you a leg up if you need to switch to a different technology where they are also doing MVC -- say RoR or Java/Struts.
The disadvantages:
Microsoft's implementation is new and not as mature.
Few third-party "controls"/plugins for round-trip use -- generic grids and such, though there are lots of plugins on the client-side via jQuery.
Requires unlearning some paradigms from WebForms to effectively use it.
The framework doesn't do as much heavy lifting for you; you'll have to learn some Javascript and write more client-side code because the framework won't inject it for you.
WebForms is a great framework, but it does requires for you to dig in and understand it. And yes, you should still be an expert in HTML and JavaScript. Every complaint that I ever hear about WebForms comes from someone who didn't take time to understand WebForms. Here are my answers to a few of them.
ViewState is Evil and will slow down the page
This reminds me of the programmers who made everything a global variable. You can certainly do it, but you SHOULD NOT! It's the same with WebForms and ViewState. Don't use ViewState unless you need to, and then only sparingly. There is nothing wrong in adding 1000 characters of view state to the html, if it will bring better user experience and/or speed up development time. You can experience the same problem in MVC by littering the page with hundreds of hidden input controls, and yes I've seen it. And by the way, ViewState is not "magical" it simply stores some data in a single input control and also encrypts it for good measure.
WebForms generates "ugly" html and is littered with long ids
Well, first of all, nobody actually looks at generated hmtl (did you look at google.com for example, it's a mess?!). Second, if you really care about generating specific html, it takes less than an hour to create your own re-usable component or control, with html of your choosing. Or you can take existing control, override rendering and use that control instead. Once again, you have to know where to go and how to do it, but once you know, it will be a great productivity boost without any sacrifices. Long ids are automatically generated to ensure uniqueness across the page. If you ever get a chance to develop a complex MVC view, you'll notice that you will inventing your own long id pattern, so that you can parse the form fields correctly on posting.
WebForms disallows multiple forms per page
I've been developing for 10 years and only once did I need multiple forms. And then I figured out that I didn't. You do have to understand HTTP requests and responses and how to achieve them with WebForms, but if you do, you'll never need multiple forms, nor will you ever think about "forms" at all.
WebForms pages are not testable
Absolutely not true. Even if you don't like MVP (which I don't), there are other techniques to test anything you want to test. It is true that if you just use pages in WebForms as is and put all logic in code-behid, it's probably not going to be testable and it's not a good idea. However, just like in MVC or Windows Forms applications, you can and you should, at least for complex views, create intermediary layers such as views and controllers. I prefer encapsulating functionality into user controls which implement an interface or inherit a base class. Then the page on which user controls reside on acts like a "master controller". Individual views, or user controls in this case, can be tested because they all implemement an interface or base class.
JavaScript is hard to do in WebForms
JavaScript is actually easier to implement in WebForms than in MVC. You sure have more options! But once again, you have to know WebForms well in order to realise this. In WebForms you can "inject" javacript with reusable components and controls. Or you can use it just like in MVC or plain HTML after changing a setting on the page to keep ASP implementing id naming scheme.
Having said all this, what does WebForms have to offer that MVC does not? Encapsulation and reusability of presentation components is by far the biggest, in my opinion. For complex views, I develop individual components (server or user controls) and than a custom controller or presentation factory weaves all of them into place. Additionally, design-time html is far cleaner in WebForms than in MVC, making design and styling a lot easier for properly trained graphic designers. It's cleaner because there is no programming code in design-time html, only markup (I don't use data binding expressions). And of course prototyping is much much easier in WebForms. For prototypes I will normally ignore all of the best practices and resort to wizards and ugly code-behind code that hits the database directly.
I could go on, but the main point I'd like to make is that WebForms and MVC are very different patterns and require different sets of knowledge and mindset to deliver great solutions. Both require as much of Web/HTTP/CSS knowledge as you can get. If I had to make one recommendation, generally, but not always, for high-traffic public website (such as blog) I may lean towards MVC. For complex web application, either internal/Intranet or membership external/Internet application, I would lean towards WebForms.
WebForms work fine and if you like them, continue to use them.
Three of the big advantages to MVC model as I see it are:
ViewState is gone, which could create a fairly sizable amount of traffic over the wire.
URLs can be remapped to mean something as is all the rage now.
Scaffolding. I don't know, personally I think this is satan and encourages terrible programming habits, but other seem to think its a beautiful idea.
It also encourages a a proper separation between business logic and presentation by enforcing the Model-View-Controller pattern, but good WebForm code can mostly do that as well.
So, really, if you are fine with the overhead of WebForms, and ok with ugly URLs and don't want scaffolding, stick with WebForms.
EDIT: Oh, I did miss one major advantage of "clean" urls. And MVC application is much friendlier for SEO. It also gives you fine control over HTML, but frankly, I don't consider that much of a step forward.
I think part of the problem, is that many people don't realise that MVC isn't an M$ invention, nor is it a replacement for webforms. Certainly, people like "new" things, and people like to throw buzzwords around, particularly to improve their resumes...
Finally .NET developers have some choice, and with that choice, they are being thrust some degree of responsibility for the decisions they make. I'm not surprised many webforms developers are nervous about this responsibility. It's not been there before. Ultimately, it can make you a better developer, or a worse one. It's now up to you.
People loved webforms, because it was better than ASP (Classic). And yes, in 5 - 10 years, I'm sure someone/group much smarter than I, will evolve a new paradigm/pattern.
Be careful with the sheep lable, as in a way, by holding onto a vendor specific pattern (webforms) you are potentially a bigger "sheep".
MVC is now across a variety of platforms, and means your potential to develop meaningful and stable solutions to problems can be dramatically increased. Or decreased. It's ultimately up to you. If you're not ready to go, then wait for ASP.NET MVC to mature. But don't close your mind to anything, particularly a pattern that is very very well established!
I recommend reading Rob Connery's extremely inflammatory blog. He certainly strummed my pain with his fingers! Then go and read RoR stuff, Cake, and Struts. All of these will start showing you the vision that the guys who brought MVC to .NET have (~ish) and hopefully will inspire you to see problems differently!
There have been several, more detailed, answers here, so rather than repeat anything they have said I'll try to keep my answer a bit more succinct. You shouldn't, necessarily use MVC over webforms, just as you shouldn't use webforms over MVC - they are both tools and are more, or less, appropriate in different situations. I was first exposed to MVC quite a few years ago on J2EE, when .NET was first coming out (I'm not sure the ASP.NET MVC was available at that time). It gives a really nice, clean framework and gives more "web" applications (i.e. request/response), but you can also add in a lot more client-side functionality using AJAX - I have done some really funky things using AJAX on a php app I wrote a while ago and that is all usable under MVC.
There are some things that MVC does better and some things that webforms do better, but if you don't know both technologies you can't choose the best one for the current project you are doing, so please don't do yourself a disservice - go and learn MVC. Even if you never use it directly, it may still give you useful "theory" knowledge you can apply in other tools. I try to learn as many different things as I can, as the more strings to my bow I have, the less likely it is that I will not be able to solve a problem (for example, in that php app, I used php, hooked into a bit of ASP, and even had DOS and *NIX batch/script files performing certain functions - each tool had its place and was best suited to the job to which it was allocated).
Not me. MVC is pretty cool in a resume, but for our customers (those who pay for our work), it's not a show stopper.
They usually want applications that are right, fast and secure. That's all. They will not want to change the third layer of the client part in three years ! In three years, they will change every thing or nothing at all.
Layers are fun to architect and to code, but they cost a lot to create and to maintain and they are not relevant to our customers. MVC is pretty cool but really useless and expensive.
Unless, of course, you are developping applications for 4 OS and 3 plateforms... But you will then be a minority.
:o)
This is a stupid discussion - they are different, ASP.NET MVC and WebForms are different technologies! I'm using MVC for all new projects, but when I am faced with a need for RAD I use WinForms, because it is simple and there are a lot of controls already written by gurus.
Stop discussing this. Who wants to understand difference? Just try both technologies and you will understand by yourself.

Converting from Web Forms to MVC

Has anybody gone through the process of converting a real-world business application from ASP.NET web forms to MVC? How painful was the transition? Would you say that it was worth it, overall?
I am trying to figure out if it is worthwhile to take the time to convert an application over to MVC for increased performance.
This is just an opinion but I would say don't do it. I've looked into this and have decided that we will use MVC for new apps and total rewrites because of the huge differences involved.
However I guess this really depends on what your asp.net pages looked like in the first place.
I am currently in the process of converting a couple of web form projects over to MVC. At first it was more to get familiar with the MVC, but now I actually really like how the model and the separation it provides.
The transition over has been a little hard in some area's in that there really isn't a lot of material other than some blogs, stackoverflow, and a couple of video casts. There are two books that are semi-available but, one is already kind of useless in that there have already been a number of changes to the framework that there are better ways in handling some things.
I also think you will have to really start to learn jQuery if you are already not familiar with it too. So for me - I feel like I am really learning two things as I've been doing this.
But worth it over all, I would say yes. And I think that converting a small project over is also really a great way to start.

Resources