繁体   English   中英

更改Url.Action(Action,Controller)默认功能

[英]change Url.Action(Action,Controller) default functionality

我不知道我的路由配置出了什么问题。

 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

但是@Url.Action("Index","Agent")返回

http:// localhost:61759 / agent

而不是

http:// localhost:61759 / Agent / Index

请让我知道缺少了什么:)

PS我不想打扰默认路由设置,即

  1. http:// localhost:61759应该路由到默认页面
  2. http:// localhost:61759 / Agent应该路由到http:// localhost:61759 / Agent / Index

在“默认”路由之前映射一个没有action = "Index"的路由:

routes.MapRoute(
    name: "NoDefaultAction",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", id = UrlParameter.Optional }
);

// Code below unchanged
routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

现在, @Url.Action("Index", "Agent")返回"/Agent/Index" ,“ Default”路由不受干扰:

  1. http:// localhost:61759应该路由到默认页面
  2. http:// localhost:61759 / Agent应该路由到http:// localhost:61759 / Agent / Index

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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