Using MVC for new parts of a Webforms project - asp.net

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.

Related

Integrating MVC code into asp.net forms site

I have an asp.net forms based site, and I am thinking of somehow integrating OpenForum which is written using MVC. I don't have any experience with MVC, so I'm wondering should I even bother - is it possible/makes sense to build this hybrid?
I guess you can add OpenForum like a SUBWEBSITE for the your MAINWEBSITE under IIS. It should work well because it is going to have its own BIN folder as well as web.config.
It's certainly possible. I've done it the other way around - added ASP.NET forms into an MVC site. And it may make sense (I've never used OpenForum), one could migrate to MVC this way.
If you search for "mix mvc and asp.net" there's a few resources with step by step instructions.
You can have some working side by side, but you mentioned in a comment about wanting to share master pages and user controls, and that's most likely going to be somewhere between difficult and impossible in some cases.
MVC doesn't use Viewstate which is a big part of webforms, nor does it have the concept of a postback. It's an entirely different paradigm. You can share session and also common classes and data structures, but as far as re-using view logic between them, it's most likely not going to be easy.

ASP .NET MVC 2.0 or WebFoms to develop an auction site like Ebay?

I´d like to know what is the best option to develop an auction site like Ebay with ASP .NET 4.0:
MVC 2.0
WebForms
I only worked with WebForms, but I have time to learn MVC if is the best option...
What you think?
MVC, but if you choose to use MVC do take the opportunity to write unit tests for your components. May I suggest a Test Drive Design approach?
While you are at it, you might also want to look in to Behavior Driven Design (it is like TDD, but few levels more abstracted)
This article http://www.lostechies.com/blogs/chad_myers/archive/2009/04/27/to-mvc-or-to-webforms.aspx has good arguments why you would want to use MVC over WebForms. You can read through the 4 bullet points and if they don't bother you then WebForms will be fine.
In a nutshell.
WebForms are fast to develop.
WebControls add ViewState and have
PostBacks.
If you come from another language
WebForms might not be OO enough for
you.
WebForms are difficult to Unit Test
If you anticipate a high volume site then not having ViewState and being able to unit test should be important to you.
I would recommend MVC, because I would recommend MVC for anything! It is easy to pick up, and you will probably never go back to webforms.
Besides the simplicity and the clean mark up. If you are working with any sort of generated code, the model binding makes developing pages really fast and easy. I have used a custom generated BLL and DLL, when the DataAnnotations attributes are generated all client side and server side validation is automatic.

Moving from WebForms to ASP.NET MVC

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.

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.

Resources