简体   繁体   中英

How to route Mvc Controller action when there is subdirectory?

This type of url works: ABC/CSDS?id=314

Folder Structure:

Controllers - Folder ,ABCController - Class ,CSDS = Action

Global.cs file has:

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "ABC", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

How to make change for subdirectory url like

ABC/TESTN/CSDS?id=314 to go to

Controllers - Folder ,ABCController - Class ,CSDS = Action

Currently it says "The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable"

How about adding a rule like this:

routes.MapRoute(
            "Default", // Route name
            "{controller}/TESTN/{action}/{id}", // URL with parameters
            new { controller = "ABC", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

Warning, not tested, I don't have the tools installed at work :(

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM