How can I make an MVC POST return me to the previous page?

后端 未结 3 1086
遥遥无期
遥遥无期 2021-01-14 00:41

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

    [HttpPost]
    //[Authorize(Roles = \"admin\")]
    public ActionResul         


        
3条回答
  •  隐瞒了意图╮
    2021-01-14 01:37

    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();
    

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

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

提交回复
热议问题