AJAX表单提交后重定向 [英] Redirect after AJAX form submission

查看:107
本文介绍了AJAX表单提交后重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用MVC 4,我有一个包含一个局部视图形式的 @ Ajax.BeginForm

Using MVC 4, I have a partial view form which contains an @Ajax.BeginForm.

表单提交的如预期,结果是我的主要观点异步显示。

The form submits as expected, and the result is displayed asynchronously in my main view.

我想在我的控制器的一个条件是,如果某个参数是真的对我的表,然后将其重定向到一个全新的页面(而不是显示的结果在我的主视图)。

I want a condition on my controller that if a certain parameter is true on my form, then it redirects to a whole new page (instead of displaying the result in my main view).

当我试图返回RedirectToAction ,在表单正常显示,而不是忽略了AJAX和重定向到一个全新的页面的DIV整个视图显示。

When I tried return RedirectToAction, the whole view displays in the div that the form normally displays in, as opposed to ignoring the AJAX and redirecting to a completely new page.

有谁知道我能达致这?

推荐答案

您可以使用返回的JavaScript 来实现它。

public ActionResult MyAction()
{
    if (parameter)
    {
        return JavaScript("window.location = '" + Url.Action("Action", "Controller") + "'");
    }
    //Do something here
    return PartialView("ParitalView", Model);
}

这篇关于AJAX表单提交后重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆