tags:

views:

1125

answers:

8

Hi

I have played with MVC in CakePHP and I like the pattern but what are the features and benefits in asp .net and why should I change to MVC instead of web forms?

Any advice welcome.

Thanks

A: 

You can move away from the WebForm way of doing things, which you may or may not view as a benefit. It is more similar to how you work with other Web technologies and programming languages. You have more built-in features for things like REST and so forth. These are just a couple.

BobbyShaftoe
+7  A: 

The following are some of the benefits of using ASP.NET MVC.

  • You get REST URLS like /category/1/7243

  • You don't have to use the ".aspx" extensions (you never really did, but now it is easier to avoid).

  • Very clean, controlled HTML output. Less of what will show up is hidden from you, so you have a lot more control over the generated HTML.

  • Client side code becomes much easier to use since you have more control over the HTML. One problem with using JavaScript with WebForms is that naming containers cause the controls on the page to have strange names.

  • Testing becomes much easier. Webforms where very difficult to test. Because of the controllers instead of the pages themselves handling things, testing becomes much easier.

  • It becomes far easier to optimize URLS for search engines. With WebForms one needed to use URL rewriters which merely hid what the real URL was.

  • With WebForms there was a sense of state. Pages maintained their state between posts. This made things a little bit easier, but this obfuscation hides how interactions between the client and the server actually occur. MVC gives you much more control over the client-server interaction.

Brendan Enrick
+1  A: 
  1. It will take you a lot less time to code the same functionality in asp mvc than in web forms.
  2. The code will be a lot more easy to read and mantain.
Drevak
How will you "code faster" in ASP.NET MVC compared to ASP.NET Webforms?
Andrei Rinea
I'm just starting with MVC framework, so anyone with more experience probably can tell you more reasons but..-No postbacks, no events and no codebehind files to code. Just the controller actions and your model.-Data binding...-Html helper...You don't code faster, you have to write a lot less code.
Drevak
A: 

I'm not 100% on the MVC technology yet, but I'm considering it for my next ASP.Net app. I found this article quite useful as a start and there are some really good videos on the site as well.

littlechris
+1  A: 
  1. MVC allows (and encourages) you to write testable code. Even if you're not into the whole TDD development process, MVC allows to easily unit test your application.
  2. You gain complete control over the rendered HTML again. It just looks like a step back from Webforms at the beginning, but is actually very flexible and powerful, once you get the hang of it.
kay.herzam
+3  A: 

In my opinion the three primary benefits are amenability to testing, a more loosely coupled architecture, and a better fit with Web protocols (REST, if you will). Using MVC you can unit test much more of your code. Basically everything but view code can be unit tested with standard test frameworks. Unit testing WebForm code can be very difficult because the underlying components are hard to mock and it is tied so closely to the markup. In MVC they've introduced more easily mocked framework classes and there is clear separation of concerns.

The clear separation of concerns also makes your code more loosely coupled. In WebForms there is a tight coupling between codebehind and the markup. There has to be because they are part of the same object (the Page). With MVC you split responsibilities for rendering the page (the view) and responding to input (the controller). More over the view never updates the model directly, leaving this interaction to the controller. This makes your code more understandable because it is clear where certain kinds of activity take place. If you want to know how a certain piece of HTML is generated, it is clear that you need to look in the view -- and the view only.

Lastly, WebForms follows and event-driven model that is closer to WinForms than to web programming. As such, you often have to jump through hoops to make it work the way you want on the web. There's an impedance mismatch, if you will, between the web paradigm and the WebForm paradigm. MVC embraces the web paradigm -- http protocols map directly onto actions. Done correctly, the actions are more RESTful as well which helps the user to infer from the URL the action being taken. I find this to be both more intuitive to use and to work with.

tvanfosson
A: 

One downside you should be aware of is that ASP.Net MVC doesn't allow the use of the web form controls, default or custom. You'll have to jump through some hoops if you want to use a custom user control on a view.

That said, the MVC platform is quite good at separating business logic from the UI.

SergioL
+5  A: 

The first thing to take in mind is the "direction" between them:

  ---------- More control over details --------->

ASP.NET Web Forms ------------------------------------- ASP.NET MVC

 <--------- Ready to use Building Blocks -------

This could be the first "thing" to understand the directions to make a choiche, after that the difference/benefits of each one are:

ASP.NET Web Forms

  • RAD
  • More easy development
  • Rich controls ecosystem
  • Familiar as the development approach to Windows Forms development

ASP.NET MVC

  • Clean Separation of Concern (Soc)
  • Full markup control
  • Enable TDD (Test Driven Development)
  • Enable and makes easily REST
  • More easy client-side integration (Javascript)
  • Multi View Engine (this is really cool!)
  • Stateless (No ViewState)
  • No postback support
  • Extensible and WEB 2.0 Enabled

These are the key elements everybody strongly says as the major differences which in firt place could help to make a good choice. I thinks switching to ASP.NET MVC from we forms it's a good choice, the advantages are more and more (take for instance the Design approach in which involves developers like patterns) the granularity of the control over things it's the power of the framework, it's however clear that this could depend by situations.

The last thing to take present is about the learning curve, switching to mvc for web forms developers could not be so immediate.

Hoghweed