A detailed understanding of the MVC framework

Source: Internet
Author: User

I started to get in touch very early. NET development, has been in the framework of 2.0, so for the MVC architecture, have heard, but not specifically used, recently and outside friends, have learned that their company in the use of MVC architecture, so they find the relevant information to understand what MVC is.

MVC represents "MODEL", "VIEW", and "CONTROLLER". ASP. NET MVC is a different architecture from traditional ASP. NET Web development. Web applications developed using MVC are more friendly to search engines.

Using the MVC pattern development requires a framework above Microsoft. NET Framework 3.5.

MVC is how to interact with the browser.

Like normal Web server interactions, MVC programs use the same way to accept requests and return information to the browser.

MVC Inside the architecture

The full ASP. NET MVC architecture is based on the Microsoft. NET Framework 3.5, and LINQ is also used.

MODEL What is it?

1. The MVC model is basically a C # or vb.net class.

2. Model will be accessed by controller and view at the same time.

3. Model is used by controller to transmit data to the view layer.

4. The view layer will use model to display the data on the page.

VIEW What is it?

1. The view layer is mostly ASPX paging files that do not include background code.

2. In the view layer, all the pages can be generated and formatted HTML.

3. You can use inline code in the view layer for dynamic page development.

4. Requests from the ASPX page in the view layer can only invoke methods in the controller.

CONTROLLER What is it?

1. Controllers are basically classes of C # or vb.net that inherit system.mvc.controller .

2. Controller is at the heart of the entire MVC architecture.

3. The methods in the Controller class are used for the corresponding browser or view layer requests.

4. The controller uses the model layer to transfer data to the page in the view layer.

5. Controoler uses ViewData to transmit any data to the view layer.

MVC naming conventions for file structures and files.

In the development of MVC program, it is very important to use standard file directory structure and file naming standard.

At the root of the program, there must be 3 directories, model, View, and Controller, respectively.

Like the normal ASP. Three directories, the root directory must also have a Global.asax file and a Web. config file.

Root [Directory]

· Controller [Directory]

o Controller CS files

· Models [Directory]

o Model CS files

· views [Directory]

o View aspx/ascx files

· Global.asax

· Web. config

ASP . NET MVC the operating life cycle

Here's how an MVC schema program executes a browser request.

A description of each step that is involved in the following graphic.

The first step, the browser request.

User in the browser, enter a URL: http://xxx.com/home/index/, this time a browser request is generated.

Step Two, global.asax. the role of MVC routing.

This URL will first be captured and interpreted by the Application_Start () method in the Global.asax file. From the URL of the request, the Controller, method, and ID will be interpreted.

So in http://xxx.com/home/index/, we will get:

L Controller: Home

L Method: Index ()

L ID: null

The third step, Controller layer with the calling method.

Now MVC will look for the class of the home controller in the controller directory. A controller class contains different methods.

A class can contain more than one method, but MVC only requests a method that is interpreted from the URL, which is the index () method.

When this method is called, a pure string is returned, or the HTML code that will be displayed by the view layer.

Fourth Step, call the View layer.

Calling view returns the view (). Invoking the view layer will access the specified ASPX page in the view directory and generate the HTML code that will be returned to the browser.

In this example, the controller is home, and the method is index (). So calling view () will return an HTML code from/views/home/index.aspx.

Here, the entire execution process is over. That's how an MVC architecture works.

Related Sites

· ASP. NET MVC Developer Center

· ASP. NET MVC Framework official forum

· ASP. NET MVC Framework documentation

· ASP. NET MVC Contrib provides MSMVC extensions

My micro-blog: http://weibo.com/szhmn
Agile Life Blog:
Http://blog.sina.com.cn/scrumme
Http://blog.163.com/scrumme
http://www.cnblogs.com/scrumme/
Welcome reprint, Reproduced Please specify: Reproduced from the Agile Life website
This article is from the "He Mengning" blog, make sure to keep this source Http://blog.sina.com.cn/scrumme

A detailed understanding of the MVC framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.