我怎样才能让一个MVC POST回到我的previous页? [英] How can I make an MVC POST return me to the previous page?

查看:140
本文介绍了我怎样才能让一个MVC POST回到我的previous页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的动作是从记录列表屏幕调用。

I have the following action which is called from a screen with a list of records.

    [HttpPost]
    //[Authorize(Roles = "admin")]
    public ActionResult Edit(EditViewModel itemView)
    {

一旦动作已经完成,我想回到那里的行动是从所谓的页面。不过,我不想刷新该页面。我只是想用类似于浏览器中的previous按钮东西回去填充屏幕。当我点击保存现在我的行​​动做以下这不是我想要的:

Once the action has completed I would like to return to the page where the action was called from. However I don't want to refresh that page. I just want to go back to the populated screen using something similar to the "Previous" button in the browser. Right now when I click "save" my action does the following which is not what I want:

return RedirectToAction("Index");

是否有某种方式来重定向到previous页面MVC3?

Is there some way to Redirect to previous page with MVC3?

喜欢的东西的功能#1后,我点击编辑,编辑它返回到后一个答案。

Something like the Stackoverflow functionality after I click edit to edit an answer where it returns to the post.

推荐答案

根据关闭$ C $,看起来你已经有了一个分页屏幕,具有点击每一行的编辑能力。下面是我如何在过去的解决了这个问题。

Based off the code you've given, it looks like you've got a paginated screen, with the ability to click edit on each row. Here's how I've solved this problem in the past.

在索引页,页面加载时,无论是从主索引或寻呼方法,添加以下内容:

On the Index page, when the page loads, whether it be from the main index or a paging method, add the following:

Session["CurrentUrl"] = Request.Url.ToString();

所以,现在,在你的编辑页面POST方法的末尾,这样做:

So now, at the end of the POST method for your edit page, do:

return Session["CurrentUrl"] == null ?
    Index() :
    Redirect(Session["CurrentUrl"]);

这篇关于我怎样才能让一个MVC POST回到我的previous页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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