簡體   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