views:

517

answers:

6

Can anyone explaine me, what is MVC, why we use it and how we can use it. Benefits of using this? and can we use ASP.NET MVC in ASP.NET 2.0 (VS 2005)

+7  A: 

You'll use MVC when you need total control over the HTML output from ASP.NET. It also allows for better/easier unit-testing. It is based on a Model View Controller architecture.

Scott Gutherie introduces it well here: Scott Gu's Blog

Ken Pespisa
Greg Beech
+3  A: 

Model View Controller (MVC) Also Microsoft ASP.NET MVC Framework. It is built using stuff in VS.NET 2008. It is best deployed on Windows 2008 Server. It will work on Windows 2003 Server but you loose some of the cool bits.

Benefits of the ASP.NET MVC Framework include:

  • REST like urls i.e. /products/1/456
  • No aspx file extensions shown on your site.
  • Very clean output model, more like Classic ASP then ASP.NET WebForms.
  • Much easier to create a testable site then with WebForms.

Downsides of ASP.NET MVC

  • It is in Beta
  • It should be run on Windows 2008, if you use Windows 2005 you will need to give an extension for all your pages.
  • It is very new.
Darryl Braaten
With Windows 2008, without any addon it will make the URL's like "/products/1/456" or we need to install some extras like http://urlrewriting.net/149/en/home.html ??
Prashant
That is correct, no addons are needed with Windows 2008 to get clean urls.
Darryl Braaten
A: 

Check out Rob Conery's work on the MVC Storefront

Andy May
+4  A: 

ASP.NET MVC is a Microsoft-tagged implementation of Model-view-controller Pattern for creating web applications, which allows for clean separation of concerns from your business layer(the Model) and your presentation layer (the View fed by Controllers). It is an alternative to using Microsoft's Webforms technology, and allows for easy unit testing, which can be all but impossible using the Webforms method.

E Rolnicki
+3  A: 

MVC is a way of separating a program into three separate units:

  • Model: handles data access, business logic and such.

  • View: generates the user interface.

  • Controller: handles input from the user interface, possibly retrieves info from the model, and depending on that info returns a view back to the user.

Benefits:

  • easier to maintain when e.g. the data access logic is kept separate from the user interface

  • possible to unit test the different parts separately

  • specific to ASP.NET MVC: usually smaller rendered page sizes when compared to ASP.NET web forms

ASP.NET MVC is Microsoft's technology for implementing the MVC pattern in a web site. It is an alternative to ASP.NET web forms, which somehow is win forms for the web. ASP.NET MVC is by many considered to be cleaner and faster than web forms, but usually requires a greater knowledge of html, javascript...

There are more details here: ASP.NET MVC. The current ASP.NET MVC Beta version requires .NET 3.5.

Ole Lynge
Is ASP.NET MVC separates logic's and DA layers same as SUBSONIC ?
Prashant
@Prashant: I don't know.
Ole Lynge
+2  A: 

MVC is a design pattern where the responsibility for displaying data is delegated to the View components, the responsibility of handling user and system input is delegated to the Controller components, and the responsibility for handling the business logic and the data is delegated to the Model components. ASP.NET MVC is an implementation of the MVC pattern for ASP.NET web programming.

ASP.NET MVC constrasts to ASP.NET WebForms where no clear division of responsibilities is expected (though good designs often attempt to enforce an MVC-like design). In WebForms, typically, view rendering, I/O handling (web requests) and business logic responsibilities are often mixed between the mark up and codebehind in ASPX pages. For example, in WebForms you can embed a SqlDataSource with selection logic directly in your mark up and tie it to a GridView. This is very difficult to test that the selection logic is working using unit tests. In ASP.NET MVC the selection of data would be handled by a controller action which generates view data to be passed off to and rendered by the view. The proper operation of this controller action (it's just a method on a controller class) can much more easily be checked using unit tests.

ASP.NET MVC uses REST-based urls, rather than the WebForm PostBack model for user interaction. MVC can use any HTTP method, with the standard expectation that RESTful urls are the norm. In WebForms, one typically sees only GET/POST methods being used.

While ASP.NET WebForms is relatively mature and has a number of controls developed for it, including third-party controls, ASP.NET MVC is still in Beta (as of 12/2008) and has many fewer controls available. Some would argue that is perfectly acceptable since one aspect of MVC is to give the developer greater control over the view rendering. Others might find this a serious drawback and may wish to wait until more controls are developed that work with the MVC model.

For comparison to other languages/frameworks, see Ruby on Rails (Ruby), Java Struts or Spring MVC (Java), and Django (Python), among others.

tvanfosson