Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When and why should I consider asp.net MVC?

I've noticed a lot of talk about asp.net MVC lately, but I haven't come across a clear or compelling description of when, where or why I would want to use it over WebForms.

Let's say I wanted to build a small web application that allows a person to advertise some items online. The website will have 4 use cases:

  • Search adverts
  • View listings
  • View item
  • Place an advert

Let's assume:

  • I'm not particularly interested in unit testing my controller. The page will either render the list of items correctly, or it won't.
  • I am interested in more control over the HTML markup.
  • I'm not interested in using the latest buzz technology just for the sake of it.
  • I am interested in using the tool that is best suited to the job in terms of productivity, performance, maintainability & simplicity of the end solution.
  • I don't want to have to work around a bunch of nuances to get something simple to work.

So, my questions are thus:

  • What are the fundamental differences between the two models?
  • In which scenario is one better than the other?
  • What are the gotchas with asp.net MVC (I'm aware of the gotchas with WebForms)
  • For our sample app, what would I gain by using asp.net MVC instead of WebForms?
  • For our sample app, what would I lose by using asp.net MVC instead of WebForms?
  • Is it feasible to mix and match models within the same small application?

Thanks to anyone who spends the time to contribute an answer.

like image 601
Winston Smith Avatar asked Nov 21 '08 10:11

Winston Smith


3 Answers

  • What are the fundamental differences between the two models?

WebForms try to mimic WinForms development by allowing you to reuse lots of pre-made controls, and by faking web application state via the hidden _VIEWSTATE mechanism.

MVC is a pattern designed to help you separate your data (Model), business logic (Controller) and presentation (View). It adheres more to the true nature of the web : RESTful URLs, stateless.

  • In which scenario is one better than the other?

In my opinion, for an intranet application making heavy usage of controls, WebForms can be useful at reducing development time, because thanks to the designer you can create your UI very quickly and let the framework manage the app's state automatically.

For any other project, especially a public website, even a small one, I think MVC is the way to go.

  • What are the gotchas with asp.net MVC (I'm aware of the gotchas with WebForms)

I'd say there is some learning curve to fully understand the MVC pattern and its power. Also, since the framework is still in BETA you can expect the API to experience some minor changes before release.

Since JavaScript is not hidden from you in MVC, it would also require some time to learn if you're not familiar with it. jQuery greatly simplifies this though.

  • For our sample app, what would I gain by using asp.net MVC instead of WebForms?

You'd gain better control over HTML markup and Javascript behavior, a cleaner separation of concerns and some easily testable codebase (even if you don't seem interested in unit testing it).

  • For our sample app, what would I lose by using asp.net MVC instead of WebForms?

You'd lose the 'drag and drop' quick way of building your pages and the application state management.

  • Is it feasible to mix and match models within the same small application?

In some ways, yes it seems.

I'd recommend watching this talk by Phil Haack, who gives a good overview of the framework and invites Jeff Atwood to talk about how he built StackOverflow with it.

He explains how SO is using some WebForms controls for CAPTCHAs which render themselves into the view.

like image 166
Franck Avatar answered Oct 20 '22 00:10

Franck


The primary difference is that MVC is more like "regular" web development that the rest of the programming world uses, whereas standard ASP.NET was designed to make it brain-dead easy for Windows developers to become web developers. I learned web programming by learning Ruby on Rails, and MVC seems like it is becoming the .NET version of Rails.

MVC is much more oriented around standards compliance, unobtrusive javascript, and separation of concerns than regular ASP.NET. You'll need to understand how HTML and CSS work together. You'll learn a LOT more javascript as you master MVC. One of the biggest advantages of MVC to me is that you can use jQuery to do some amazing AJAX stuff easier and BETTER than you can in regular ASP.NET.

If you're just now learning web development then I strongly encourage you to learn MVC. You'll be able to transfer at least some of your new skills to other frameworks in the future.

If you're looking for which to learn to quickly get a web development job, then I'll have to strongly suggest ASP.NET.

Once MVC is RTM'd I think we will see a slow and steady adoption curve and as it matures MVC may become the primary framework for creating websites with ASP.NET. I hope so at least!

like image 3
Tad Donaghe Avatar answered Oct 19 '22 22:10

Tad Donaghe


  1. The biggest difference between ASPNET MVC and is WebForms is the lifecycle of an page, no difficult(unnecessary) postbacks, clean coding, enz.
  2. There are no rules for that
  3. ???
  4. REST-full website, Separation of logic
  5. Design-time support, can't use third-party webcontrols
  6. Please don't mix it together. If you really want to use the WebForms model you could use the MVP pattern, Billy McCafferty wrote exellent articles on that design pattern

I'm redesigning some of my applications from the MVP-pattern to MVC-pattern, not because MVC is better but I would like to use the newest techniques offered by MS(pattern itself is quite old).

like image 2
JSC Avatar answered Oct 20 '22 00:10

JSC