2013-09-25 78 views
0

我使用LowerCasedDashedRoutes包在MVC项目,并写了这条线......路由问题,索引操作必须明确调用?

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

routes.Add(new LowercaseDashedRoute("{action}", 
    new RouteValueDictionary(
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }), 
    new DashedRouteHandler() 
) 
); 

当我想从URL中移除首页控制器的名称和简单的调用动作我这个伟大的工程想在该控制器内。但是,当我想要去一个不同的控制器说代码与像http://www.mydomain.com/codes一个网址我想代码控制器显示的默认指数行动。相反,我得到一个404,除非我输入http://www.mydomain.com/codes/index我需要编写什么才能使其工作?

+0

为您需要定义一个新的路由 –

+0

听起来不错,你能为我提供这条新航线的一些代码? –

+0

你能帮助代码吗? –

回答

0

添加这样的路线

routes.MapRoute(
    "Codes", 
    "codes/{id}", 
    new { Controller = "codes", action = "Index", id= UrlParameter.Optional }, 
    new[] { "YourProjectName.Controller" } // namespace of the code controller 
);