Moving from WebForms to ASP.NET MVC - asp.net

i know ASP.NET and i would like to learn and make a new project in ASP.NET MVC.
Is it easy to move from asp.net to asp.net mvc? Will the knowledge i have so far be helpful?
Im asking because i will have only few days to learn asp.net mvc and i want to know whether it's possible...
Cheers

I think you will find this questions (and its answers) very helpful.

Is it easy to move from asp.net to
asp.net mvc?
My answer to this would be a question back to you. Do you understand HTTP? Is web forms sort of magical to you, or do you have a firm grasp of what the abstraction is doing?
The reason I ask is that MVC sort of strips away a lot of the "magic" that web forms gives you in terms of treating a stateless protocol as actually having state. I tend to think of out of the box web forms development closer to classic windows forms development then normal web development. There are good and bad things about that.
What MVC is doing is bringing closer to what is actually happening in HTTP and in the end giving you more control and power over that. What you won't find in MVC is slew of drag and drop datagrid type controls, but it will make it easier to write AJAX heavy sites with common javascript libraries and clean html, as well as enable you to more easily write testable code.
Will the knowledge i have so far be helpful?
Without knowing what your "knowledge" is, it is hard to say. Obviously c# and vb are the same it's not like its a new language.
It really comes down to what type of web developer you were in asp.net forms. If you found yourself annoyed at how IDs were generated and how the html output of controls was horrible and that the framework was making it hard to do what you want then you should be fine.
If you were like I stated before, more of a drag and drop type of web forms person than MVC might be a bit challenging, but I would say its a good challenge and something that will ultimately make you a better web developer.
The only way you'll really know is if you try... There are tons of resources out there to get you started.
Hope that helps. Don't be afraid to ask questions on here as you go, there are tons of MVC devs on this site.

If you've ever used technologies like ASP classic, Coldfusion, PHP, etc. where you intersperse regular markup with server-side logic, then you will be able to pick up the "view" syntax pretty easily. The controllers are pretty simple to grasp once you get the hang of it, and the model shouldn't have to change from what you are used to. The hardest part for me to grasp when first learning ASP.NET MVC was the routing.
Like anything else, it will take some effort before you learn the "right" ways to do certain things, and you will initially be a bit less productive in the new technology. But in the end it is worth it.

Personally, I felt that ASP.NET MVC was far easier to learn than ASP.NET WebForms.
Run through the NerdDinner tutorial. It should take you about half-a-day. I think you'll find the simplicity refreshing.

Related

Learning Web Development starting with ASP.NET MVC

I have been working with C# for past four years at the enterprise level. Now, I have taken a decision of moving to Web side of the things. Since I am well versed with C# and WCF I naturally zeroed in on ASP.NET as I need not learn a new Programming language. Learning just the Web Framework will suffice.
I have read a lot regarding MVC, so starting out with MVC 2.
My Question is Will I face any roadblocks if I learn MVC without learning Web Forms? Keeping in mind that this is my first foray into Web Development?
Looking forward to some good suggestions.
I was in your exact same position. The only problems you may have is wrapping your head around postbacks and what tha means. Having said that, MVC2 will teach you how to write better code instead of the typical spaghetti that comes asociated with webforms.
If you're new to MVC2 I'd recommend buying Wrox Professional ASP.NET MVC2 from writer Scott Hanselman.
Learning web development these days is hard as you need to be an expert on so many different things!
You need to learn HTML/CSS/JavaScript(ie, JQuery)/Json regardless of the server side framework you are using if you are creating “rich” web applications.
I would say starting with ASP.NET MVC is not a bad option before moving onto ASP.NET Web Forms. You are likely to hit both going forward, but as ASP.NET MVC does not hide what’s going on so much, I think it may be a better start.
However if you just wish to create simple forms on the web, it is hard to beat ASP.NET Web Forms, but as soon as you wish to do something more advanced, the Web Forms complex page cycle will give you pain.
If you're looking to apply your web skills to enterprise environments, you'd probably find a lot of environments still leveraging Web Forms. Outside of that, I can't imagine it would really hurt you that much.
The bigger thing about web development is getting familiar with HTML/CSS/JavaScript(ie, JQuery). The skills learned there are applicable to either environment. You'd probably be able so switch back end frameworks rather painlessly as long as you're used to c# and all the web stuff previously mentioned.
I think it depends on what type of applications you are going to be developing. I believe web forms would be easier for you to learn with the background you already have in WCF. But it might not be worth it if the applications you are developing are better suited for MVC rather than web forms.
My recommendation would be to determine what type of applications you are going to be developing and then look at the strengths and weakness's of each and then determine which one you are going to focus on.
You most probably won't. There are some concepts that belong to the web-application environment (session, caching, etc) that are common but you'd have to learn about them anyway. They are two separate frameworks so nothing very specific about one of them could help you with the other.
You will undoubtedly run into issues when knowing a "new" way of doing things without having been brought up in the "old" way of doing things. It's unavoidable, really. I'd suggest learning the basics of WebForms code if possible, if for no other reason than to be able to trudge through it when necessary. Of course, if you find yourself in the position of having to support a WebForms application, you'll learn by doing just like anything else.
This question reminds me of my early days in .NET (which were the very early days of .NET in general) and trying to find assistance with various issues. I was an entry level developer, hitting up forums and such with questions. Everywhere I went, people weren't really adopting .NET just yet. They were all old Windows platform developers, whereas .NET was my first Windows development (I was all UNIX/Linux in school). Invariably, nearly every question I asked was answered with something suggesting that I "just use COM." Of course, I wasn't familiar with this. It was "the old way" and I was using "the new way."
It was difficult to work past that, and you'll likely face the same issue here. Basically, when people have made a career out of doing something the one single way they know how, they tend to expect everyone else to know it as well and will cling tightly to it as their bread and butter. You can be better than that, but it'll require patience :)
I assume that your development experience included Windows Forms. In terms of the transition from Windows Forms to ASP.NET WebForms, there's no doubt that would be an easier transition. Whether that would be the best transition is another question. And I believe the answer is without a doubt, no.
MVC allows you to gain an understanding of the way the Web works. Understanding GET and POST, Requests and Responses, not to mention HTML, CSS, JavaScript, et al.
I would not hesitate to recommend MVC.
I don't understand why you don't want to learn Web Forms. Learning Web Forms is just like learning abc's. You'll learn it as you go along with MVC. My suggestion is, Just go with the flow in your learning of MVC and you'll be surprise that you're already learning Web Forms.

Usefulness of asp.net MVC framework as opposed to coding MVC style with regular asp.net?

I am new to the asp.net world (but not new to .net) and I have been playing around with various things to see how I want to architect a web application I am developing. In my playing around I have decided I did not want to use asp.net's controls, as I have done enough php and ruby on rails to be decently familiar with regular HTML, and a decent amount of javascript.
I see a lot of comparisons between asp.net webforms and asp.net MVC, however when ti comes down to it I am not seeing that much of a difference (and I'll admit that it's probably me missing the differences rather than them not being there). I already have coded my asp.net application using a MVC type of architecture (aspx has the view, aspx.cs has the controller code, and models are separate classes in the app_code directory).
If I do not intend to use asp.net controls and just intend to use pure html and javascript, what are the advantages of using the MVC framework? As of right now, the only one that I am seeing is routing, and I'm sure if I look more I can find easy ways to do custom routing without using the whole MVC framework.
Anyways, if anyone could go into details of asp.net webforms minus the asp controls versus mvc framework, I would be greatly appreciated.
You're going to find a number of differences and reasons to use MVC over WebForms but it's going to depend on whether those differences are important to you or your project. Routing is definitely a big advantage for MVC. Although you can implement custom routing configurations in WebForms it's significantly less intuitive.
Another big advantage is unit testing. Along with an IoC container and a mocking framework, MVC makes unit testing a cinch. It's much easier to isolate actions and behaviors with MVC and test those specifically.
A third advantage is that MVC will help reduce the spaghetti code you're going to write. If you're not planning on using any User Controls then it won't be long before you're missing the HTML helpers in MVC. The Html, Url, ViewModel, TempData, etc make working with raw HTML much easier.
The inherent validation in MVC is also impressive. It's getting better in MVC2 and now with the integration with client side validation libraries it will save you a ton of time and add a lot of functionality.
No more VIEWSTATE.
There are many others but again it depends on whether those features are important to you. Good luck with your decision!
ASP.NET MVC is built on interfaces, which makes it extensible, easy to write unit tests for, and encourages clean, loosely-coupled architecture.
If you're using 'classic' ASP.Net without using any of the server-side controls, there's not much of ASP.Net that you're using -- it's basically classic ASP with .Net instead of VBScript behind it at that point.
Giving up webcontrols is the biggest reason not to use ASP.Net MVC. If you're fine giving that up, I'd just use ASP.Net MVC and be done with it. It's got all the parts you'd need to write yourself anyway, and the parts you don't like, you don't have to use.
In my playing around I have decided I
did not want to use asp.net's
controls, as I have done enough php
and ruby on rails to be decently
familiar with regular HTML
Thats not a good reason to decide against ASP.NET controlls. The importand thing about ASP.NET is Viewstate. It allows you to use event driven programming in Webapplications. This makes a lot of things very easy and productive.
Anyway - as you know ruby on rails I guess you will pick up ASP.NET MVC pretty fast.
First up, if you use ASP.NET MVC you'll be using a supported framework that has books, online resources and hundreds of blog posts surrounding it.
Second, I suspect you need to play with ASP.NET MVC to see it's power. There is way more than WebForms in ASP.NET MVC. For many, the fact that WebForms is optional (you can use different view engines) is a major plus.
For me, the extension points, the cleaner code, and the unit-testability of everything I do are major reasons to never go back to ASP.NET "classic".
My recommendation to you is to get a decent tutorial (look for the Nerd Dinner tutorial), play with ASP.NET MVC, and find out for yourself.
Note: ASP.NET MVC is not for everyone, and if you're heavily into the post-back mechanisms in ASP.NET, or have a heavy investment in server and user controls, then you might not want to take ASP.NET MVC right now. But for your next project you should at least know what your options are.

Do I need ASP.NET MVC?

I realize that ASP.NET MVC has all the hype. I have my doubts that I need it, but wanted to explain my potential project:
This is an internal LAN application. It is doing CRUD operations and a little reporting.
The user base is small (< 12 people) and there is not tons of data
There is not a huge number of screens (Maybe 20)
I don't care about URL rewriting
My view state is typically small (like a DealID or ClientID)
Even though I don't have a full mastering of Page Lifecycle, I do understand Postbacks and don't have a problem coding for it.
I believe in Layering and am familiar with the M-V-P pattern and other patterns.
I want to do some Unit testing, but heck 25-50% coverage is better then what most apps.
The app will have a little AJAX for search screens, but don't see it being overkill.
So what do you think? While using the "sexy" technology is cool, is it necessary?
No, it's not necessary. It sounds like you've already made up your mind. If the application isn't all that critical and you're more familiar with web forms, just do it the way you know how to. I think ASP.NET MVC is worth learning, but it isn't the right solution for every project. Go and try it out in your free time so that when this situation comes up again, you'll have more options available to you.
No you don't strictly need MVC but are you asking whether you should learn something new or use what you already know for an internal project? An internal project might be the perfect place to try out something new.
As was said, it's not necessary. However, if you're doing a basic CRUD application (and it sounds like you are), MVC would make that nice and easy.
You mention you're moving to project management. Do you think any of the projects or products you look into will be using MVC? If so then at least you'll have some familiarity by learning it with this small application. This means it is necessary, if you need it as a PM, but you do not require it just to build the app. It could run with anything you choose.
Incidentally, ASP.NET MVC is new, not MVC, not by any stretch of the imagination. I know you did not say it was, but you mention hype. I cannot help but think Java and other folks are saying, "We've been doing this for years and years."
You can use both.
Create a Visual Studio Web Application (not a website), and you'll be able to use both if needed.
You'll just need to add a reference to MVC and setup the routing.
Webforms and MVC
It's not necessary, no, but there's no reason why you can't use webforms or MVC.
If you feel comfortable working with webforms, then go down the webforms approach. If, however, you feel the need to broaden your knowledge of architectural patterns, then ASP.NET MVC is a pretty nice thing to use.
If unit testing is important to you, go with MVC. Everything else you mentioned, though, points to WebForms.

Using MVC for new parts of a Webforms project

I really like the MVC "way" and have actually enjoyed learning ASP.NET MVC (I never liked ASP.NET Webforms but I didn't know why until now). The problem is I'm about to inherit a bunch of Webforms code and wondered if I'll be able to add new things to the codebase with MVC instead off using Webforms. I suppose it depends a lot on how authentication is set up and if the code is set up in a way that I can include some library or something and just use those function or if I'll have to recreate them or gasp duplicate them somewhere else. What should I worry about? Should I just stop messing with MVC and get working on Webforms or can I make it work together so that if I need to modify something from the Webforms codebase I can just remake it the MVC way as I move along?
I would recommend attempting to only add new stuff using MVC and convert over the legacy webforms code as you can.
This is a pretty decent post of putting them both together in the same project:
http://www.chadmyers.com/Blog/archive/2007/11/30/asp.net-webforms-and-mvc-in-the-same-project.aspx
Scott Hanselman has a post that talks just a little about it in his blog. If you want to start going down the MVC route then go for it. I think it probably depends on how big the ASP.NET Webforms app is.
Well, MVC is built on top of Asp.Net so they should be able to play well together. The question is if the data is structured in such a way that it would lend itself to using the MVC framework and ideology.
Also think about the maintainability of it -- and not just for yourself, but for others. It might be better to just stick to webforms depending on where the application state is at. If you have to start doing more work just to get the application to work, it might not be worth the hassle.

Migrating Classic ASP - Webforms or ASP.NET MVC? [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.
I'm doing some maintenance on a classic ASP application for my client, and as I'm looking through the ASP, the following question comes to mind - would it be easier to convert a classic ASP app to ASP.NET MVC or ASP.NET WebForms?
In many ways, it appears that at least the HTML of ASP might be easier to convert to MVC than it would be to rip out the HTML chunks and turn them into ASP.NET controls, repeaters, datagrids, etc. Plus having to add in handling and logic for ViewState, etc. might be added work.
I don't think my client will be requesting any upgrade like this, so this is just theoretical.
Let's assume that this ASP code is written very well (which isn't always true of course) so really the question is, will a best-case-well-designed ASP site migrate better to MVC than WebForms?
(Note that I'm very new to ASP.NET MVC, so I might be missing something crucial here).
It depends a lot on how the classic asp app is structured.
The server tag mixed in with HTML is similar to asp.net mvc but MVC is not as messy (or not supposed to be). You might be able to move the classic asp presentation code to a MVC view easier than to a web form. Also classic asp apps were usually developed with the statelessness of the web in mind. There probably is not anything in your classic asp that matches postabacks or viewstate. Classic ASP also uses normal html elements as opposed to asp.net webform controls. In these respects it matches MVC a lot closer than webforms.
If you do not know asp.net webforms or asp.net mvc I would say MVC is the way to go.
If you know webforms very well and don't know much about MVC I would say webforms is the way to go.
But, if your client for some reason does want a redevelopment of the site I would say go with MVC. It's always nice to have a client pay for part of your experience development as long as you can deliver.
On another note I'm always taken aback when I come across a client who wants me to do work on their classic asp site. In every single case the site is a mess. The worse part is that they are usually filled with huge security holes.
I think in a lot of cases it could be easier to convert to MVC than Webforms. Most classic ASP apps demonstrate very little separation of concerns so the biggest task is probably exactly that, seperating out the logic into data access, business logic, business entities and UI components. In doing that it could well be easier to convert the inline ASP code to a view, the business logic into controllers and the business entities into the model.
I don't think one would be easier to convert then the other.
You can code ASP.NET almost the same as you code ASP if you wanted putting a few crucial elements in the codebehind that you could access in the aspx. No databinding, no gridview and no repeater. The view state is there to help you can is easy to figure out, it is not necessary to use it if you don't want and can be turned off in the web.config and turned on with a page attribute. Web forms also have an AspCompat mode which allows access to Request and Response objects or asp, which will allow for page by page conversion if desired.
As for MVC.net, the method for displaying the HTML is quite similar. That in my opinion is where the similarities end. You would still need to separate out all you logic into the MVC model.
Coming from ASP and going to Web.Form and now MVC.Net I can tell you that WebForms were a little annoying/frustrating to learn, with 90% of the MS tutorials teaching you the worst possible habits IE (SQL connections on the page, dragging datasets around in designers). However, once you get past that one is able to do a lot of thing much more quickly then in asp(pagination or build a simple datatable with editing for example), I have however STILL never seen a large webforms project with an n-tier design that I thought was easy to follow, implement and use.
MVC.NET is like a godsend. It forces patterns and practices down your throat, it has strict rules that are adhered to by most. It allows for easy code coverage and separation of concerns. After being frustrated with webforms for years it finally feels like I am not hacking things together when attempting to do something that I cant drag off the tool bar.
I personally would try webforms so you will know how much better MVC is when you start using it.
There is more to ASP.NET-MVC than the apparent similarities between view code and ASP inline code. There is all the Model and Controller parts to consider which is very different from the way most ASP is written.
That said I would say that MVC would be the best place to start.
IMO WebForms attempt to hide html too much for my liking and may cause your project to take longer than you would like due to converting a lot of html into the webforms controls.
On the other hand MVC allows you to reuse some of this logic while making your application much more maintainable and with the appropriate Architectural Pattern your application can be developed and refactored much quicker than any WebForms project.
I say MVC all the way!
Either way, it's always best to start from scratch and implemented only the logic.
I started ASP a long time ago (more than 12 years ago) and only in 2006 I moved to ASP.NET 2.0, not even today I know all, but I do know pretty much what I do everyday at work.
In my opinion now, and looking back to my knowledge of ASP I would go to Web Forms instead of MVC, first, it's a language that it's in the "market" some some yeras now and very used across the world, while MVC is still in Beta, so, not suitable for production environment (says Microsoft - even if this site is written in MVC).
I do tend to make confusion with MVC diagram still, and there are more tricks than I want to learn if I need to do a fast change of one ASP project.
It depends. The ASP.NET MVC is no silver bullet and in many ways takes a few steps backwards in terms of developer productivity.
If you have a tight budget and need to get this done fast I believe ASP.Net is the way to go since it has the wealth of controls like grids, paging, validation etc that you can use right out of the box. Using these controls will no doubt save a lot of dev time. All of these controls that most consider pedestrian by now in ASP.NET all have to be created from scratch or taken from the Internet when you use the ASP.NET MVC project.
On the other hand if you have the time and budget now and going forward, and you want to have a solution that is rock solid, and more easily lends itself to test driven development, the ASP.NET MVC is probably the best choice.
Definately ASP.NET MVC is better in terms of style. (That said, you don't have to use Repeaters and other silly controls in a WebForms app, you can simply use inline code just like you would in MVC.)
MVC in general though would be an easier port, give you a better structure and be a more pleasant experience.
Web Forms is more object-oriented, while MVC is like classic ASP on top of .NET code. Model design should be the same using Web Forms or MVC. The only difference is that Web Forms has an object-oriented abstraction to the UI and MVC uses functions and code snippets instead of classes to organize UI code.
ASP.NET MVC is better than Web Forms for automated unit testing of the UI. However, automated unit testing in general is bad practice and even worse for the UI. Manual testing is the best way to build a quality application and to make the best use of development time. Creating automated unit tests is a waste of time and you end up with junk code to maintain with the core code. Lots of developers like automated unit tests because they think they are proof their application works, which is false. They also are trying to avoid designing applications using UML so they are using test driven development to design using code which is responsible for poorly designed applications. With TDD, you are refactoring code you wrote poorly without thinking about the big picture using models in the first place.
So MVC is useless. Web Forms uses a better object oriented model whereas MVC is more like old style classic ASP and other older design patterns. This is 2010 and MVC is dead. Web Forms is like ORM for the UI.

Resources