First, create a new MVC project because it's only installed on my server. Net4.0 therefore select the 4.0 framework. Once the project is established, we can see the directory structure on the right.
Where Global.asax is the entry for the entire program
Arearegistration.registerallareas (); Webapiconfig.register (globalconfiguration.configuration); Filterconfig.registerglobalfilters (globalfilters.filters); Routeconfig.registerroutes (routetable.routes); Bundleconfig.registerbundles (Bundletable.bundles);
The registration of these four profiles corresponds to four files in the App_start, respectively
The role of bundles is to merge the CSS or JS files that you use, to solve the limit that the browser can only load 6 links at the same time, to speed up the site's access.
The role of filter is to define a filter, which can be preceded by a qualified filter in front of each action, such as [HttpPost], which restricts the action to be accessed only by post.
Route is the routing rule for site access.
Routes. Ignoreroute ("{resource}.axd/{*pathinfo}"); Routes. MapRoute ( name: "Default", URL: "{controller}/{action}/{id}", defaults:new {controller = "Home", action = "Index", id = urlparameter.optional} );
The access method is shown in the URL. Default is Website/home/index
The controller corresponding to the controller,action in the Controlllers folder corresponds to the action in each controller, and the ID is the parameter to be passed in.
We can see that the controller and view correspondence are as follows
Each controller corresponds to a folder in the view, and each method corresponds to a cshtml page in the folder.
This is a simple way to return to the Home page view, and we can interact with the cshtml page by viewbag the data. (X-real-ip is the header of the access IP I defined in nginx)
In the corresponding index.cshtml, we can also use @viewbag.ip to get the data passed in.
When we run the website, our IP will be displayed on the
In the Views folder, there is also a _layout.cshtml
The front plus _ is not directly accessible, layout.cshtml is the template page, we can define the entire Web site header and footer, while referencing all the CSS and JS files, and then loading the intermediate content through @renderbody ().
Home Build--mvc