用于签出的MVC4路由子文件夹目录



我需要做什么才能将这些URL映射到我的路线?

example.com/checkout?o=1234
example.com/checkout/shipping?o=1234
example.com/checkout/payment?o=1234
example.com/checkout/review?o=1234
example.com/checkout/receipt?o=1234

在RouteConfig中,我定义了以下内容:

 routes.MapRoute(
         name: "Checkout",
         url: "checkout",
         defaults: new { controller = "Checkout", action = "Index", o = UrlParameter.Optional }
     );
 routes.MapRoute(
          name: "checkout Prefix",
          url: "Checkout/{controller}/{action}/{o}",
          defaults: new { controller = "Shipping|Payment|Review|Receipt", action = "Index", o = UrlParameter.Optional }
          );

控制器文件夹为:

 Controllers
      CheckoutController.cs
            Checkout
                 ShippingController.cs
                 PaymentController.cs
                 ReviewController.cs
                 ReceiptController.cs

当我切换订单,但先切换Checkout Prefix时,它会打乱"Checkout?o="路线。当我把结账路线放在第一位时,第二位永远不会被击中。

您认为o是路由的一部分的假设是不正确的。查询字符串不会作为匹配的一部分进行计算。

此外,您应该在约束中指定正则表达式,而不是将其指定为默认值。

routes.MapRoute(
    name: "Checkout",
    url: "checkout",
    defaults: new { controller = "Checkout", action = "Index" }
);
routes.MapRoute(
    name: "checkout Prefix",
    url: "checkout/{controller}",
    defaults: new { action = "Index" },
    constraints: new { controller = "Shipping|Payment|Review|Receipt" }
);

相关内容

  • 没有找到相关文章

最新更新