"Original" questions about MVC's own new action,controller hint that the page could not be found

Source: Internet
Author: User

I. Examples:

1. For example, I created a new ~/view/shop folder under the Indexshop.aspx, then in the Controllers folder will be corresponding to a ShopController.cs controller class.

2. In the Global.asax, create a new article:

Routes. MapRoute (
Name: "Shop",
URL: "{controller}/{action}/{id}",
defaults:new {controller = "shop", action = "Indexshop", id = urlparameter.optional}
);

3. It is also very important to pass the parameters in the return View () method to the new. aspx string, as an example, in all the action methods in ShopController.cs.

Public ActionResult Indexshop ()
{
Return View ("Indexshop");
}

Two. Principle

(a) Positioning

1. Routing Configuration:

In MVC, routing is responsible for determining which controller action to handle a particular URL request. The default MVC project adds a generic route that uses the following URL habits to resolve a specific URL request, which is divided into three sections, including braces: {Controller}/{action}/{id}

The extension method used to register the route is Maproute (), which is registered (in the App_start/routeconfig.cs file) when the program is started, for example:

Routes. MapRoute (
Name: "Default",//route name
URL: "{controller}/{action}/{id}",//url parameter
defaults:new {controller = "Home", action = "Index", id = urlparameter.optional}//default URL each parameter value parameter value
);

1. Positioning controller

in ASP. NET MVC, the system uses the "Convention first" principle, and when an application starts, ASP. NET MVC looks for all the available controllers in the assembly. These controller classes inherit from the System.Web.Mvc.IController interface or her subclass, and the name has a "controller" suffix, and when the router framework determines which controller it needs to access, it removes the suffix to get the name of the controller class. So when you need to use Contrller, directly use it to remove the "controller" suffix after the name can be, such as Auctionscontroller refers to the controller class is auctions, and HomeController refers to the "Home."

2. Positioning the View

The ASP. NET MVC Dependency convention is to look up this view file in the Views folder under the root directory of the Web site, or more specifically, to put the view files in a folder named after their corresponding controller name.

Therefore, if the MVC framework wants to display a view for the HomeController index operation, it will look for a file named index under the/views/home folder. If the view folder does not find a folder corresponding to the controller name, or if the corresponding file is not found under this folder, the MVC framework will continue to look in the/views/shared folder.

"Original" questions about MVC's own new action,controller hint that the page could not be found

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.