我在MVC项目中使用了LowerCasedDashedRoutes包并写了这行...
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.Add(new LowercaseDashedRoute("{action}",
new RouteValueDictionary(
new { controller = "Home", action = "Index", id = UrlParameter.Optional }),
new DashedRouteHandler()
)
);
当我想从URL中删除 Home 控制器名称并在该控制器中调用我想要的操作时,这非常有用。但是,当我想要使用 http://www.mydomain.com/codes 这样的网址向不同的控制器说代码时,我希望默认的索引操作要显示的代码控制器。取而代之的是,除非我输入 http://www.mydomain.com/codes/index ,否则我会得到一个404。我需要写什么才能让它发挥作用?
答案 0 :(得分:0)
添加类似此路线的内容
routes.MapRoute(
"Codes",
"codes/{id}",
new { Controller = "codes", action = "Index", id= UrlParameter.Optional },
new[] { "YourProjectName.Controller" } // namespace of the code controller
);