简单 MVC 路由配置正在截断来自 URL 的操作

Simple MVC Route config is truncating action from URL

就在我确定我了解路由的功能时,当我去更改默认路由时弹出这个问题。

这是整个配置 (RegisterRoutes):

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

  routes.MapRoute(
      name: "Login",
      url: "Login",
      defaults: new { controller = "Account", action = "Login" }
  );

  routes.MapRoute(
      name: "Unauthorized",
      url: "Unauthorized",
      defaults: new { controller = "Home", action = "Unauthorized"}
  );

  routes.MapRoute(
      name: "Default",
      url: "{controller}/{action}",
      defaults: new { controller = "Home", action = "Index" }
  );

页面上有一个link是使用@Html.ActionLink("Loan Management", "Index", "Certification", routeValues: null, htmlAttributes: new { })生成的。

出于某种原因,该函数的输出是一个锚元素,其 href 指向 "/Certification",而它应该是 "/Certification/Index"。其他 link 似乎生成良好(没有 "Index" 作为动作的)。

为什么 "Index" 从认证 url 中被截断?

routes.MapRoute(
      name: "Default",
      url: "{controller}/{action}",
      defaults: new { controller = "Home", action = "Index" } \right here
  );

这就是原因。 Index 是默认值,因此如果您停止操作,则假定为 Index

http://localhost/Certification

http://localhost/Certification/Index
功能相同。