ASP.NET MVC framework and building tutorial (recommended)


1、 Introduction to MVC

MVC: model view controller (MVC). MVC is a software development architecture model.

1, model(Model

Model objects are application components that implement application data domain logic. Typically, model objects retrieve model statesState and store it in the database. For example,Product Object may retrieve information from the database and manipulate the information,Then write the updated information back to the Product In the table.

2, view(View

The view is the display application user interface (UI) Components of. Usually, this UI Is created with model data.ProductAn example view is the edit view of the table, which is based on Product The current state of the object displays a text box and a drop-down columnTable and check boxes.

3, controller(Controller)

The controller deals with user interaction, uses the model, and ultimately selects the view to be rendered for display UI Components of. stayMVC In an application, the view only displays information; the controller is used to process and respond to user input and interaction. For example, controlThe controller processes the query string values and passes them to the model, which may use them to query the database.

4. Attach the diagram:


2、 Why is there MVC? What are the advantages and disadvantages

1. Why MVC Web Form Existing problems:

1. Response time: time consumption of service request

2. Bandwidth consumption: how much data can be transmitted at the same time:

ASP.NET Developers are very familiar with viewstates because it can automatically save the state returned by post and reduce development time. But this reduction in development time can be costly, and viewstate increases the size of the page. In the loading test, compared with MVC, we found that the page storage of viewstate is increased by twice.

3. Unit test: unable to execute automatic test, manual test is required Webform pages inherit“ System.Web.UI . page “class. However, these classes are not as reusable and instantiated as ordinary classes. In other words, it is never possible to perform the following operations in the weform class:

WebForm1 obj = new WebForm1();


Since the backend code class cannot be instantiated, unit testing is also very difficult, and automated testing cannot be performed. It must be tested manually.

2. Advantages of MVC framework

· simplify by dividing applications into models, views, and controllers.

It does not use view state or server based forms. This makes the MVC framework particularly suitable for developers who want to fully control the behavior of their applications.

It uses a front-end controller pattern that handles web application requests through a single controller. This allows you to design an application that supports a rich routing infrastructure.

It provides better support for Test Driven Development (TDD).

It is ideal for web applications supported by large development teams, as well as web designers who need strict control over application behavior.

3. Disadvantages of MVC framework

The connection between the view and the controller is too close: the view and the controller are separated from each other, but they are closely related components, and cannot be reused independently.

The view is inefficient in accessing model data: depending on the model operation interface, the view may need to be called multiple times to obtain enough display data.

3、 Three layer frame construction

1. Overview

a. Data access layer(EntityFramework): mainly responsible for the data access management, not otherOperation to provide method call for business logic layer.

b. Business logic layer: it is mainly responsible for the processing of business logic and the operation of data layer. That is to say, put someData layer operations.

c. Presentation layer: mainly for the user’s request acceptance, as well as the data return, provides the application for the clientVisit.

d. Three layer framework reference diagram:

2. Building MVC three-tier framework project

1、 Create ASP.NET MVC project

a. Open Visual Studio

b. Action: File > New > Project > OK

c. On the pop-up window, select MVC > OK

2、 Add 3-tier project

1. Bll (business layer)2. DAL (data layer)3. Model (entity layer)

Right click the solution and select Add Project

3、 Add three levels of reference

1. The citation relations among the three layers are as follows:

Dal references model

♢ Bll references DAL and model

♢ created ASP.NET MVC projects reference Bll and model

2. Reference method: right click the corresponding project and select reference (you can also right-click reference in the project)

4、 Understand the structure and function of directory

The above article ASP.NET The MVC framework and build tutorial (recommended) is the small editor to share all the content, I hope to give you a reference, also hope that you can support developeppaer more.