Home Build--mvc

Source: Internet
Author: User

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

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.