Prior to learning the MVC knowledge point, because it is not used in the work. So after a long time forget part of the mess, and then to the beginning of a small review:
One. What is the MVC pattern?
MVC (Model-view-controller, model-View-Controller) mode is actually a software architecture pattern.
two. Differences between MVC and WebForm workflows ( images and content from http://www.cnblogs.com/QLeelulu/archive/2008/09/30/1302462.html)
WebForm, when user requests a page (for example, http://www.51mvc.com/blog/index.aspx), the workflow is as follows:
As can be clearly seen, the WebForm program will go to the root directory of the site to find the blog directory of the index.aspx file, and then by the index.aspx page codebehind file (. cs file) for logical processing, The codebehind may include the database to fetch the data and then be presented to the user by the Index.aspx page.
Then look at the MVC program, when the user requests a page (for example, http://www.51mvc.com/blog/index.aspx), its workflow:
As you can see clearly, in MVC:
The URL requested by the client is mapped to the appropriate controller;
The controller then processes the business logic, perhaps taking the data from the model;
Then a controller chooses the appropriate view to return to the client.
For example, we run an ASP. http://localhost:62106/home/index This URL that accesses the Home The action of the index in the controller, see:
So, how did the URL be located in the controller?
---through routing, and the specific URL is routed to which controller, which can be completely defined by ourselves. We can take a look at the Global.asax file:
So, how is view returned to the client?
There is a return View () method in the action method in the---controller. By default, it returns a view with the same name as the action. Under the ASP. NET MVC default view engine (Webformviewengine), view is accessed by the following path:
/views/{controller}/{action}.aspx
For URL http://localhost:62106/home/index, by default, the return view () in the Index action returns to the view, performing the following two steps:
1. To find views/home/index.aspx files;
2. If cannot find views/home/index.aspx this file, will go to Share directory search: views/share/index.aspx;
3. If it is not found, it will throw a view exception not found.
However, when we go directly to access views/home/index this path, it will appear 404 error, said to find you not to file, why?
---because in MVC, it is not recommended to go directly to the view, so we built an ASP. NET MVC program by default in the Views directory with a Web. config file, which has the following content:
means that all the files in the Access view directory will be handled by System.Web.HttpNotFoundHandler, so do not put the resource files (css,js, pictures, etc.) in the views directory. If you really want to put in the views directory, please modify the Views/web.config file.
Introduction to MVC