如何解决孩子的行为是不允许执行重定向操作,其他的答案不能解决 [英] How to fix Child actions are not allowed to perform redirect actions, other answers does not fix
问题描述
ASP.NET MVC2观点:
ASP.NET MVC2 view:
<%@ 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>
CheckoutController:
CheckoutController:
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();
// http://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);
}
pressing形式提交按钮会导致异常
pressing form submit button causes exception
Child actions are not allowed to perform redirect actions
由于code显示最upvoted答案从
As code shows most upvoted answer from
<一个href="http://stackoverflow.com/questions/1538523/how-to-get-an-asp-net-mvc-ajax-response-to-redirect-to-new-page-instead-of-inser?lq=1">How得到一个ASP.NET MVC Ajax响应重定向而不是插入视图到UpdateTargetId?
时,试图修复它,但是这会导致其他错误:浏览器尝试打开网址了window.location ='/结帐/ CompleteOK
is tried to fix it, but this causes other error: browser tries to open url window.location = '/Checkout/CompleteOK'
如何解决这一例外?一切看起来都OK,还有在其他的答案中所述任何部分景色。 我试过ALS O操作使用方法='后'的形式,但问题仍然存在属性。
How to fix this exception? Everything looks OK, there is no partial views as described in other answers. I tried als o to use method='post' attribute in form but problem persists.
推荐答案
而不是调用的公众的ActionResult CheckoutCompleteOK()
的帖子,删除操作,并创建一个HTTP POST操作为公众的ActionResult PaymentByBankTransfer()
。
Instead of Calling public ActionResult CheckoutCompleteOK()
on post, remove that action and Create a HTTP Post Action for public ActionResult PaymentByBankTransfer()
.
然后返回 RedirectToAction(完整);
在PaymentByBankTransfer POST方法
Then return RedirectToAction("Complete");
in PaymentByBankTransfer post method.
我认为这将解决您的问题。
I think this would solve your problem.
这篇关于如何解决孩子的行为是不允许执行重定向操作,其他的答案不能解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!