【发布时间】:2017-07-04 05:23:33
【问题描述】:
我有这个路由配置:
routes.MapRoute(
"routeB",
"routeB/{action}/{id}",
new { controller = "Sample", action = "IndexB", id = UrlParameter.Optional });
routes.MapRoute(
"routeA",
"routeA/{action}/{id}",
new { controller = "Sample", action = "IndexA", id = UrlParameter.Optional });
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
我的 Sample 控制器包含这些 Action 方法:
public ActionResult IndexA(string id)
{
return View("Index");
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult IndexA()
{
return RedirectToAction("Confirmation");
}
public ActionResult Confirmation()
{
return View("Confirmation");
}
public ActionResult IndexB(string id)
{
return View("Index");
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult IndexB()
{
return RedirectToAction("Confirmation");
}
如果我登陆 localhost/RouteA 页面并进行 POST(通过按钮),它会将我重定向到 localhost/RouteB/Confirmation。
如何让页面重定向到 RouteA/Confirmation 页面?
谢谢。
【问题讨论】:
-
向我们展示视图
Index -
查看索引可以在下面找到:@{ ViewBag.Title = "Index";布局 = "~/Views/Shared/_Layout.cshtml"; }
索引
@Html.Partial("OrderForm") -
OrderForm: using (Html.BeginForm("IndexB", "Sample", new { @id = "OrderForm" })) { @Html.AntiForgeryToken() }
-
是的,这解决了这种情况,但我希望它能够以两种方式工作。如果我键入 RouteB 并进行 POST,在这种情况下它将转到 RouteA/Confirmation。我想一直保持相同的路线,不管是哪一条。
标签: c# asp.net asp.net-mvc asp.net-mvc-routing