ASP. NET MVC is Microsoft's Web development framework, combining the effectiveness and cleanliness of the model-view-controller (MVC) architecture, the most cutting-edge ideas and technologies of agile development, and the best parts of the existing ASP. It is a complete alternative to the traditional ASP. NET Web form. In this article, I'll show you why Microsoft has created ASP. NET MVC, which is different from his previous technology.
Asp. NET history
To understand the history of ASP, you need to understand the history of ASP. Asp. NET was created in 2002. He combines ASP. NET WEB Form Technology, ASP.
Through Web Forms, Microsoft hides HTTP (and its stateless) and HTML by modeling the user interface (UI) into a series of hierarchical server-side control objects (many developers are unfamiliar with him at the time). Each control maintains and records its own state during an HTTP request, renders itself as an HTML element when needed, and automatically connects client events (such as button events) and the corresponding server-side event handler code. In fact, Web Forms is a large abstraction layer designed to send a classic event-driven user interface (GUI) on the web. His idea was to make web development feel like Windows Form development. Developers do not need to handle a series of interdependent HTTP requests and responses. They just need to care about the UI logic, and Microsoft seamlessly delivers the Windows desktop developers ' armies to the Web application world.
Asp. NET disadvantage
Web forms is not all that bad, Microsoft has made a lot of effort to improve his flexibility, simplifying the development process, and even taking some features from ASP. Web Form is better when you need to develop quickly (a relatively less complex web app can be developed in one day). But unless you are very careful in your development, you will find that the applications you create are very difficult to test and maintain.
Main benefits of ASP.
In October 2007, Microsoft announced a new MVC development platform, built on the ASP. NET core platform, designed to adapt to innovative technologies such as rails and the direct response of Web Form critics. The following section describes how the new platform overcomes Web forms and how to bring the ASP back to the edge of the era.
It is important to differentiate between MVC schema patterns and the ASP. NET MVC framework. The MVC pattern is not something new-back to 1978 at Xerox PARC's Smalltalk project-but now as a model, he has gained a huge welcome in Web applications. There are several reasons:
The user interacts with the MVC application in a natural loop: the user issues a behavior, changes its data model as a response system, and sends an updated view to the user. Then repeat the loop. This is very handy for sending a series of HTTP requests and receiving a response to a Web application.
Web applications force a combination of technologies (such as databases, HTML, and execution code) to separate them into different tiers. The patterns generated from the process of combining these layers naturally map to the MVC concept. Asp. NET Framework implements the MVC pattern, which improves the separation of concerns in the implementation process. In fact, ASP. NET MVC implements quite a portion of the MVC pattern, especially for Web applications.
The MVC framework is built on a series of separate. NET interface-based components, and is based on an abstract base class. You can easily replace components, such as replacing routing systems, view engines, and controller factories with different components that you implement yourself. Presumably, the MVC framework gives you three options:
Tightly control HTML and HTTP
Asp. NET produces clean, standard markup HTML. Based on the HTML helper class method, the output conforms to the standard, but there is a more philosophical change than the Web Forms. Instead of creating a HTML,MVC frame that you can't control, you are encouraged to write simple and elegant markup that is decorated with CSS.
Of course, if you don't want to throw away some of the complex UI element widgets that are readily available, such as date controls or hierarchical menus, ASP. NET MVC is easy to use the best UI frameworks such as the jquery UI or the bootstrap CSS framework.
The pages generated by ASP. NET MVC do not contain any view state data, so they are smaller than the pages generated by the ASP.
ASP. NET MVC works seamlessly with HTTP. You can control the requests that are passed between the browser and the server, so you can control your user experience in as little detail as possible. Ajax has become very easy, without any automatic callbacks from the client to the server-side interface.
The MVC architecture lets your application start to be maintainable and testable, because you naturally detach different application concerns. However, ASP. NET designers did not stay here. To support unit testing, they made the framework design a component-targeted design, ensuring that each separate section was able to serve the needs of unit testing and mocking tools.
Testability is not just a unit test. An ASP. NET MVC application can also work well with UI Automation tests. You can write a test script that mimics the user's actions without worrying about which HTML element, CSS class, or framework generated the ID, and you don't have to worry about any changes in the HTML structure of the page.
A powerful routing mechanism
With the update of Web application technology. The URL style also changed. A URL like this:
are getting smaller and fewer. be replaced with a simpler and cleaner format below:
There are some good reasons to care about the structure of URLs. First, search engines value keywords found on URLs. Search for "Rent in Chicago" is more likely to appear in search. Second, many web users now understand URLs enough to be able to enter URLs directly at the address. Third, when people start to understand the URL structure, they are more likely to link him, share it with friends, and even read it aloud on the phone. Four, he doesn't expose the technical details, folders, and file names of your application.
Clean URLs are difficult to implement in previous frameworks, but ASP. NET MVC uses a feature called URL routing to provide the default clean URLs. This allows you to control your URL pattern and the relationship with your app. It gives you the freedom to create meaningful URLs that are useful to your users without having to obey a well-defined pattern. Of course, this means that you can easily define a style of the URL that you would prefer for a stylish rest style.
Built on the best part of the ASP.
Microsoft's existing ASP. NET platform provides a proven, validated set of components for developing efficient and efficient web applications.
First, most obviously, because ASP. NET MVC is based on the, you can use any. NET language to access the same API features-not just MVC itself, the. net extension class framework and the vast third-party. NET Framework ecosystem.
Second, the already-well-done features of the ASP-such as authentication, membership, roles, profile, and internationalization-can reduce your code when developing and maintaining the web system, and these features are as effective in the MVC framework as in the classic Web Form project. Asp. NET platform provides a rich collection of web development tools for the MVC framework.
ASP. NET MVC is open source
Unlike the previous Microsoft Web development platform, you are free to download ASP. NET MVC source code, and even modify and compile your own version.
Follow me to one of ASP. NET MVC: a good opening