Skip to main content
 首页 » 编程设计

c#之如何修改 MapRoute(添加新目录)

2024年02月03日31luoye11

我怎样才能改变我的 map 路线,这样我就可以有另一个目录,而不仅仅是 Controller 和 Action 。

我想要的是在 Controller 之前有另一个目录,这样我就可以将每个“模块”的 Controller 分开

        routes.MapRoute( 
            "Default",                                       // Route name 
            "{module}/{controller}/{action}/{id}",           // URL with params 
            new { module = "module", controller = "controller", action = "Index", id = ""} 

这就是我想要的,但是代码不起作用。我还需要更改什么才能更改 MapRoute?

请您参考如下方法:

您是否考虑过查看 ASP.NET MVC 2 的区域功能?它可以满足您将站点划分为不同“模块”的要求。

Walkthrough: Organizing an ASP.NET MVC Application using areas