ASP. net mvc 3 until I have an arrow in my knees [2] MVC project structure

Source: Internet
Author: User

The ASP. net mvc framework includes a Visual Studio Project template that helps you create a Web application that supports the MVC mode. This template creates a new MVC Web application, which is configured as a required folder, item template, and configuration file item.

1. Environment

  • Visual Studio 2010
  • Visual Studio 2010 SP1
  • AspNetMVC3Setup
  • AspNetMVC3Setup_CHS

2. MVC project structure

By default, the MVC project includes the following folders:

  • App_Data: The physical storage area of the data. This folder serves the same purpose as ASP. NET websites that use Web forms pages.
  • Content. We recommend that you add Content files, such as Cascading Style Sheet files and images, to this location. Normally, the Content folder is used to store static files.
  • Controllers. We recommend that you store Controllers here. The MVC framework requires that the names of all controllers end with "Controller", such as HomeController, LoginController, or ProductController.
  • Models, which is a folder provided for the class that represents the MVC Web application's application model. This folder usually includes code that defines the object and the logic used to define interaction with the data storage. Generally, the actual model object is located in a separate class library. However, when creating an application, you can place the class here and move it to a separate class library at a certain time in the development cycle.
  • Scripts. We recommend that you store script files that support applications in this location. By default, this folder contains basic ASP. net ajax files and jQuery libraries.
  • Views. We recommend that you store the view here. The view uses the ViewPage (. aspx), ViewUserControl (. ascx), and ViewMasterPage (. master) files, as well as any other files related to the rendered view. In the Views folder, each controller has a folder named with the Controller name prefix. For example, if the Controller is named HomeController, the Views folder contains a folder named Home. By default, when the ASP. net mvc Framework loads a view, it searches for the ViewPage (. aspx) file with the requested view name in the Views \ controller name folder. By default, the Views folder also has a folder named Shared, but this folder does not correspond to any controller. Shared Folders are used to store views Shared between multiple controllers. For example, you can place the master page of a Web application in the Shared folder.

3. Default Value of global URL Routing

In addition to the folders listed above, the MVC Web application uses the code in the Global. asax file to set the default value of the Global URL route and uses the Web. config file to configure the application. The route is initialized in the Application_Start method of the Global. asax file. The following example shows a general Global. asax file that contains the default routing logic.

 

.


1 public static void RegisterGlobalFilters (GlobalFilterCollection filters)
2 {
3 filters. Add (new HandleErrorAttribute ());
4}
5
6 public static void RegisterRoutes (RouteCollection routes)
7 {
8 routes. IgnoreRoute ("{resource}. axd/{* pathInfo}"); // directly access the. axd file in the URL mode of the route to be ignored
9 routes. MapRoute (
10 "Default", // route name
11 "{controller}/{action}/{id}", // URL with Parameters
12 new {controller = "Home", action = "Index", id = UrlParameter. Optional} // The default value of the parameter is www.2cto.com.
13 );
14
15}
16
17 protected void Application_Start ()
18 {
19 AreaRegistration. RegisterAllAreas ();
20
21 RegisterGlobalFilters (GlobalFilters. Filters );
22 RegisterRoutes (RouteTable. Routes); // register a URL route when the application starts.
23}




4. MVC Framework and sending back

The ASP. net mvc Framework routes all end user interactions to the controller class instead of using the ASP. NET Web form sending-back model to interact with the server. This separates the UI logic from the business logic and helps improve testability.
Author Yixin yiyu

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.