这是我的RouteConfig.cs
routes.MapRoute(null,
"{controller}/Page{page}",
new {controller = "Product", action = "Index", category = (string) null},
new {page = @"\d+"}
);
routes.MapRoute(null,
"{controller}/{category}",
new {controller = "Product", action = "Index", page = 1}
);
routes.MapRoute(null,
"{controller}/{category}/Page{page}",
new {controller = "Product", action = "Index"},
new {page = @"\d+"}
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
这是生成url的代码:
@Html.ActionLink("View Cart", "Index", "ShoppingCart", null, new { @class = "btn btn-orange" })
例如,当我导航到 、 、 时,它Product/Page2
运行Product/Laptop
良好Product/Laptop/Page2
。问题是,只要我当前的 URL 包含Page
段,它就会尝试重用该段来生成传出 URL。所以,如果我在Product/Page2
上面生成的 URL 将是ShoppingCart/Page2
. 我不知道如何避免这种情况。
请帮我。太感谢了。
编辑!!!
我找到了一种解决方法。ActionLink
我没有使用,而是这样使用RouteLink
:
@Html.RouteLink("View Cart", "Default", new { controller = "ShoppingCart", action = "Index" }, new { @class = "btn btn-orange" })
但我仍然想使用ActionLink
,所以请帮助我。
编辑!!!
当我生成指向ShoppingCart/Checkout
. 它仍然需要我在控制器中Index
采取行动。ShoppingCart