ASP. net mvc 5 Web programming 1, asp. netmvc
Introduction
When talking about ASP. net mvc, the first question I want to ask as a WebForms developer is: why should I use it? My understanding is: MVC is a more detailed framework, and "details are controllable" means your system is more refined. It is embodied in the application. The emergence of MVC may be catering to the increasingly sophisticated needs of Web development. As far as I know, the architecture of a large investment management e-commerce platform is ASP. NET MVC. The future trend of MVC in system application is probably a large-scale e-commerce platform. Of course, WebForms are not "abandoned". In rapid development and control reuse, WebForms are still at the forefront. Sometimes, we can mix these two technologies in the same project as needed.
Prerequisites: Windows 7 sp1 or later operating system + IE10 or later browser + Visual Studio 2013
Demo creation and directory file Introduction
1. Open VS2013 and create an MVC5 project.
OK. Select the MVC template.
The default project directory structure is as follows:
Directory file description:
Directory or file |
Content |
App_Data |
Store data files |
App_Start |
It contains four types of files: Binding configuration, filtering configuration, routing configuration, and start (verification) configuration. |
Content |
With 3 CSS files included, except site.css, the highlight is that the Bootstrap CSS/HTML framework, which is popular in foreign countries and used by Twitter, is integrated by default. |
Controllers |
Controller, which contains two class files, each representing two controllers. For more information about controller, see subsequent articles in this series. |
Fonts |
Font |
Models |
Two model (entity) Classes |
Scripts |
Js folder, including bootstrap. js and jquery-1.10.2.js. |
Views |
View, that is, the page folder. Contains the. cshtml file. For cshtml, we will introduce it in detail later. |
Global. asax |
System entry |
Packages. config |
Important: record the version information of key technical frameworks in the system. |
How MVC works
In most Web frameworks (asp, asp.net form, jsp, php ,...) the URL address is usually mapped to a specific physical file on the disk, for example,/HelloWord/welcome. php or/HelloWod/welcome. aspx, usually has a welcome on the disk. php or welcome. the aspx file corresponds to it. When an http request for a Web application is sent to the server, the Web framework submits the request processing permission to the requested file. Generally, this file generates a response sent to the client through HTML tags. This process can be understood as a "file-type request ".
How does MVC work?
The MVC framework uses another method to directly map the URL path to the server code, that is, to map the URL directly to the class rather than to the physical file.These mapped classes are called "Controller classes". They can process server requests, user input and interaction with users, and execute application logic and data logic. The control class calls an independent "View" component to generate HTML output for the request. This process can be understood as a "controller-type request ".
The following figure explains "Controller-type requests ":
Now we can perform a test to verify the "Controller-type request ". Right-click the Controllers folder to create a Controller
Select MVC5 Controller
We name the newly created Controller HelloWorldController and change the default code to (very simple, you can write your own ^_^ ):
Then recreate the project. Run. In the browser, +/helloworld after the site address (I am here http: // localhost: 55952, your port may be different), the effect is as follows:
Similarly, after the site address +/helloworld/welcome, the effect is as follows:
Through this simple example, I think you have understood and made a preliminary impression on "Controller-type requests. (The first input address can be accessed without the index method name, because the index method is the default entry .)
In fact, the above access rule can be mapped to the methods in the corresponding controller Class and Class, which is defined in the RouteConfig. cs file in the App_Start folder. This class has only one method.
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); }
This method defines the ing rules and routes that can be ignored (also called the access address type that can be ignored ).
For details about URL ing, we will go into the next chapter.
Summary
This chapter introduces ASP. NET MVC5 as an entry level, and discusses and verifies the running principle of MVC. I hope this will be helpful for children's shoes that have not yet come into contact with MVC. This chapter begins with a series and will also discuss the content of the subsequent articles in a series.
In addition, do not forget to send a sentence from the elders to everyone: if you are not interested in MVC, it doesn't matter, it is completely an "optional" item. You must know that MVC and WebForms coexist.
Finally,
If you are interested in MVC5, please stay tuned. I hope you can "recommend" it and wish you a smooth job.
Original article link http://www.cnblogs.com/hangwei/p/4255676.html