ASP.NET MVC2 视图:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcMusicStore.ViewModels.PaymentViewModel>" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
...
<form action="<%= Html.Action("PaymentByBankTransfer", "Checkout") %>" >
<input type="submit" value="Payment by bank transfer" />
</form>
结帐控制器:
public ActionResult PaymentByBankTransfer()
{
var order = Session["Order"] as Order;
ExecCommand(@"update dok set confirmed=true where order={0}", order.OrderId);
return CheckoutCompleteOK();
var cart = ShoppingCart.GetCart(HttpContext);
cart.EmptyCart();
// https://stackoverflow.com/questions/1538523/how-to-get-an-asp-net-mvc-ajax-response-to-redirect-to-new-page-instead-of-inser?lq=1
return JavaScript("window.location = '/Checkout/CompleteOK'");
}
// common method called from other controller methods also
public ActionResult CheckoutCompleteOK()
{
var cart = ShoppingCart.GetCart(HttpContext);
cart.EmptyCart();
// prevent duplicate submit if user presses F5
return RedirectToAction("Complete");
}
public ActionResult Complete()
{
var order = Session["Order"] as Order;
SendConfirmation(order);
return View("PaymentComplete", order);
}
按下表单提交按钮会导致异常
Child actions are not allowed to perform redirect actions
由于代码显示了最受好评的答案
如何获得 ASP.NET MVC Ajax 响应以重定向到新页面,而不是将视图插入 UpdateTargetId?
试图修复它,但这会导致其他错误:浏览器尝试打开 urlwindow.location = '/Checkout/CompleteOK'
如何解决此异常?一切看起来都不错,没有其他答案中描述的部分视图。我也尝试在表单中使用 method='post' 属性,但问题仍然存在。