TOC

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

Introduction:

What is MVC?

MVC是模型(Model) - 视图(View) - 控制器(Controller)的缩写,是最初在20世纪70年代开发的软件模式,当时图形用户界面处于开发的早期阶段。 MVC将应用程序分为三个方面:

模型(Model)

它负责存储数据和业务逻辑。在大多数网站中,它主要负责表现,如数据库的一个表,或者其他网站需要用到的对象。

视图(View)

视图(View)就是模型(Model)的视觉表现。在大多数网站里,无论它是一个输入框,或是一个数据显示单元,或是二者的结合,它都是向用户呈现模型(Model)的页面。视图并不需要显示出模型中的所有内容,而且一个模型可以通过多个视图来显示。

控制器(Controller)

控制器会处理你的模型(Model)和你的视图(View)之间的所有通信。在一个典型的Web应用程序中,当一个页面被加载或一个按钮被点击时,此时用户就会调用控制器的方法。如果需要的话,控制器会更新模型(Model),然后返回一个新的视图/动作(后面会有更多的介绍)。

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!