MVC5 dry articles, catalogs and routes

Source: Internet
Author: User
Tags configuration settings sqlite database sql server express

    1. MVC directory Structure Overview

folder or file

Describe

Note

/app_data

This folder is used to hold private data, such as XML, or SQL Server express\sqlite database files, or other file-based repositories

IIS will not service the contents of this folder, which means that the directory's files cannot be fetched through the Web request

/app_start

This folder contains some of the core configuration settings for your project, including routing, filters, bundles, APIs, and more

/areas

The storage folder for the zone in the program. You can also divide a large application into small pieces.

/bin

The location where the MVC program compiles the assembly and any referenced assemblies that are referenced and are not included in the GAC global Assembly cache

IIS does not service this directory. The bin folder is not visible in Solution manager and needs to be displayed for all files to be visible. You do not need to store this folder in the source controller (TFS).

/content

Static content for placing MVC, such as CSS or pictures

This is a convention but not a necessity. You can put static files anywhere, as long as you like.

/controller

Folder to place the controller

This is a convention. The controller classes can be placed anywhere because they will be compiled into the same assembly.

/models

For placing a view model or domain model class, the domain model is best placed in a dedicated assembly, and the view model is placed in that folder.

This is a convention where model classes can be defined in any location.

/scripts

For storing JavaScript libraries

This is a convention that can be stored in any position.

/views

Used to store views and sections of views, usually their associated controller-named folders are grouped

The/view/web.config file prevents IIS from servicing these directory contents. The view must be rendered through an action method.

/views/shared

Used to store layout views and shared views.

/views/web.config

This is not the application's configuration file. It contains the configuration required to enable the view to work with ASP, prevent IIS from invoking the view, and the namespace of the view is imported by default.

/global.asax

This is the global ASP. NET Application class. His background code class Global.asax.cs is used to register routes, WebAPI, bundles, and other configurations. It also involves building the code where the application is initialized, shut down, or is running when an unhandled exception occurs.

/web.config

application's configuration file

    1. URL Routing

A routing system typically has two functions:

examine the URL of the input, judging the need to request that controller and action.

Generates the output URL.

    1. To register a simple route, you need to define the route in Routeconfig and then register it in the Global.asax.cs class. Such as:

    1. Detailed routing configuration. Such as:

    1. Using attribute Routing
      1. Attribute routing is an important addition to MVC, but it violates the MVC principle of separation of concerns. By default, property routing is disabled.

      The way to turn on attribute routing is as follows:

      1. Use the route attribute tag to configure routing rules for action methods, such as:

        The route attribute tag supports the following table of parameters:

Name

Describe

Name

The name of the routing configuration that needs to be used

Template

Defines a pattern that matches URLs targeted by an action method

    1. Use the Routeprefix property annotations to define the normal prefixes for all routes in the controller.

MVC5 dry articles, catalogs and routes

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.