0

I have a post action in my MVC something along the line of:

    public ActionResult FilterData() {
        // Do some work
        // ....
        if (lastView != null) {
            return View(lastView);
        }
        return View("Default");
    }

Where do I find "lastView" so I can return the user to wherever they were at before postback?

Bill Software Engineer
  • 7,362
  • 23
  • 91
  • 174

2 Answers2

1

You could provide the URL as a parameter:

public ActionResult FilterData(string redirectUrl = null)
{
    // Do some work
    // ....
    if (redirectUrl != null) {
        return this.Redirect(redirectUrl);
    }

    return View("Default");
}
Dan
  • 9,717
  • 4
  • 47
  • 65
0

This would not scale very well, but you could create another/edit the ActionResult to pass in a parameter from the View you just came from:

ActionResult FilterData(previousViewName)
{
    if (lastView !< null)
    {
        return View(previousViewName);  // or RedirectToAction(previous'controller'Name)
    }
    else
    {

    }
}
NexAddo
  • 752
  • 1
  • 18
  • 37