This article is currently in the process of being translated into Portuguese (~34% done).


What is MVC?

MVC, acrônimo para Model-View-Controller, é um padrão de software originalmente desenvolvido na década de 70, quando as interfaces gráficas de usuário ainda estavam no início de desenvolvimento. O MVC busca separar a aplicação em três áreas:

O Modelo

Aqui é onde os dados e as regras de negócio são armazenadas. Numa aplicação web típica, esta parte representaria, por exemplo, uma tabela de banco de dados ou qualquer outro objeto que a sua aplicação possa tratar.

A Visão

A Visão (View) é a representação visual do seu modelo (Model). Numa aplicação Web típica, a View seria a página que apresenta o modelo para o usuário, podendo ser um formulário de entrada de dados, uma pagina só de apresentação de dados ou uma combinação das duas. Obviamente a Visão não precisa apresentar todas as partes do modelo e o modelo pode ter mais de uma View.

The Controller

The Controller should handle all communication between your Model and your View. In a typical web application, the methods of the Controller are invoked by the user when a page is loaded or a button is clicked. The Controller then updates the Model, if necessary, and then returns a new View (or action, but more about that later), if necessary.

The Rise of MVC

After being introduced in the 1970's, the MVC pattern didn't get much attention for the next 30 years. Early web languages, like Perl, PHP and ASP Classic didn't really focus on design patterns and even with the release of ASP.NET, MVC was still not an integrated part of it. Sure, you could apply MVC techniques to your projects, but none of the popular frameworks encouraged it in any way.

Then, in 2004, the Ruby on Rails framework was released, which was a web development framework based on the Ruby language with heavy inspiration from the MVC pattern. A lot of people believe that this put the focus back on MVC and shortly thereafter, many PHP frameworks, centered around the MVC pattern, was released. All of this made the MVC pattern hugely popular, which is probably why Microsoft decided to do an implementation of it for their .NET framework, including massive tool support in their Visual Studio IDE. ASP.NET MVC was released in 2007, but the first final version didn't see the light of day before 2009.

In the next chapters, we will look deeper into what ASP.NET MVC is all about and how it compares to the alternatives, mainly ASP.NET WebForms.

This article has been fully translated into the following languages: Is your preferred language not on the list? Click here to help us translate this article into your language!