我添加了一个自定义路由,如下所示
routes.MapRoute(
name: "Default",
url: "{coutry}/{lang}/{controller}/{action}",
defaults: new { controller = "Home", action = "Index" }
);现在,当我试图从一个控制器调用一个方法时,我遇到了一些问题,在添加新的路由之前,它工作得很好。
<a id="someId" class="link-button" href="../Documents/Create"><span>Create</span></a>现在,我唯一能做到这一点的方法就是使用像href="EN/us/Documents/Create"这样的东西
有没有办法为我的客户端保留自定义路由,并且仍然为我的管理员端保留href="../Documents/Create">方式,这是因为我在管理员端开发了几个功能,但现在我必须包括客户端的自定义路由。非常感谢。
现在有我的路线了
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "CustomRoute",
url: "{country}/{lang}/{controller}/{action}",
defaults: new { controller = "Test", action = "Index" }
);但我只能使用/es/es/测试/索引访问CustomRoute ...为什么不采用默认值?
发布于 2013-04-17 11:48:17
您只需要在默认路由后声明您的自定义路由:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index",
id = UrlParameter.Optional }
);
// SomeOther = someothercontroller
routes.MapRoute(
name: "CustomRoute",
url: "{coutry}/{lang}/{controller}/{action}",
defaults: new { controller = "SomeOther", action = "Index" }
);发布于 2013-04-17 11:52:25
您已将默认Url替换为新配置,并且它确实与此{coutry}/{lang}/{controller}/{action}格式的RouteConfig相匹配。
如果您想要接受../Documents/Create Url,则必须在末尾添加默认RouteConfig。
routes.MapRoute(
name: "CustomRoute",
url: "{coutry}/{lang}/{controller}/{action}",
defaults: new { controller = "Documents", action = "Index" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);此外,在锚标记<a id="someId" class="link-button" href="../Documents/Create"><span>Create</span></a>中,您可以编写如下代码,而不是硬编码href。
<a id="someId" class="link-button" href="@Url.Action("Create","Documents")><span>Create</span></a>
https://stackoverflow.com/questions/16051061
复制相似问题