1.2 What is ASP. net mvc?
ASP. net mvc provides another option for developing Web Applications Based on. NET Framework. It was first released in July, and now four versions have been released. ASP. NET released in January 2011
MVC 3.0 is the first version based on. NET Framework 4.0. ASP. net mvc 4.0 can run in. Net 4.0 and. net
Above 4.5.
MVC is short for Model-View-controller and is a very popular design pattern in the Web development field.
As another branch technology of Web forms, ASP. net mvc adopts different ways to build Web applications. This means you do not have to deal with aspx pages, controls, sending back, viewstate, and complex event-based page lifecycles. You only need to define the controller, action, and view. The underlying ASP. NET platform remains unchanged, like HTTP
Handler) and HTTP module (HTTP modules) are still available. You can even mix MVC and web forms in a web application. ASP. NET
MVC and ASP. NET web form will move forward side by side on the core ASP. NET Framework.
ASP. NET web pages
In Figure 1.2, you may find that the third method is based on ASP. NET.
Framework technology-ASP. NET web pages.
ASP. NET web pages and ASP. NET mvc3 are released at the same time. As a beginner, if you want to learn ASP. NET, you can select
Forms and mvc asp. NET
Web Pages technology. It is also suitable for simple website development. Many of its technologies are shared with ASP. net mvc. If you have learned ASP. NET
Web pages, so you can easily migrate to MVC development.
You can use Visual Studio to Develop ASP. NET
Web pages program, but Microsoft released a platform specifically developed for it: webmatrix. He does not have visual
The complex features of maxcompute studio only provide the functions required for web development. Introduction to webmatrix is beyond the scope of this book, but some examples in this book involve ASP. NET
Web pages. This includes the razor template engine, which is ASP. NET.
Use C # Or VB in MVC to generate HTML.
Figure 1.2 relationship between different ASP. NET technologies
We will explain all the core features of the ASP. NET Framework in this book. The following are some advantages of ASP. net mvc that you want to learn:
- Full control over HTML code;
- Full URL control;
- Better separation of concerns;
- Scalability;
- Testability;
With the in-depth reading of this book, these advantages will be presented one by one. Now, let's take a look at the underlying mode on which ASP. net mvc framework depends. Why MVC mode? Where does it come from?
1.2.1 MVC Mode
In the 1970s S, the MVC model originated from the Smalltalk development organization.
The emergence of on rails (2003) has become widespread.
The MVC pattern consists of three components:
Model-fields around software development. If you are building a blog system, the models involved may be post and comment. In some contexts, the term model may refer to a view-specific model. A view-specific model refers to a domain model that only displays the target on the user interface.
View-model rendering. A framework usually uses a view to present the content to a browser. The result is generally in the form of a markup language. For example, you can use HTML to display the content of a blog.
Controller: connects views and models, and coordinates views and models. It is mainly responsible for receiving client input, operate on the model and decide which action to execute (whether to display a view or jump to another page). In the blog system, you can use the Controller to find the latest reply information of an article and call an appropriate view, present it.
Figure 1.3 shows how views, models, and controllers are associated.
Figure 1.3 MVC component.
The Controller receives user input and builds an appropriate model to pass to the view. Both the controller and view depend on the model, but the model itself does not depend on the controller and view.
In. NET Framework, ASP. net mvc does not implement the MVC mode first. Inspired by Ruby on Rails, the open-source framework monorail introduced the MVC model in Web development as early as 2005. We are now in ASP. NET
Some of its concepts and influences can still be seen in MVC.
In addition to ASP. net mvc and monorail, there are also some other MVC-based frameworks on the. NET platform. Including: fubumvc (http://mvc.fubu-project.org, an open source convention-based framework; openrasta (http://openrasta.org), a commitment to Web application and Web Service Development, open-source projects based on the concept of resources and HTTP modules.
By introducing the MVC mode, ASP. net mvc has some advantages that ASP. NET web form does not have.
1.2.2 ASP. net mvc Improvement
As a better choice for developing Web applications on the. NET platform, ASP. net mvc solves many shortcomings of ASP. NET web form.
Closer to Protocol
The HTTP protocol is stateless. The ASP. NET web form framework tries to hide the essence of HTTP. However, ASP. NET maps an HTTP request to a method call by introducing the MVC mode. programmers with a web development background are usually very familiar with this development experience. The model has been completely simplified, and is out of the web
Complex page lifecycle based on events in form, while HTTP abstraction is minimized.
Separation of concerns
The user interface and code in ASP. NET web form are tightly coupled. ASP. net mvc advocates the separation of user interface and code (used to drive interface display. This means that programmers can better control and maintain applications, because when you change the Controller code, you do not have to change the user interface.
Enhanced Testability
By separating the application logic from the interface, ASP. net mvc makes it easy to test each component independently. You can test the Controller class separately without testing the actual user interface. Unlike traditional web forms, the MVC controller does not rely on the notorious httpcontext class, but on an abstract functional convention, so it is easy to perform automated unit tests.
So far, you have learned some advantages of ASP. net mvc. Next we will briefly learn about the new features of the 3rd versions of the framework compared with the old version.