DannyD
DannyD

Reputation: 2891

I can't figure out how to navigate to a previous page

I have two ways of navigating to a form that I'm using. However, once this form has been submitted, I would like to return to the previous page that I was on. Is there a certain url path that I can navigate to based on which page I was on previously?

I'm using just a standard form and a mvc architecture.

Here's my controller for this form:

    [HttpPost]
    public ActionResult Create(CreateConversationViewModel model)
    {
        try
        {
            _ConversationManager.Create(model.Message, model.GetReceivers(), model.SenderId);
            return RedirectToAction("Me", "People");
        }
        catch (ValidationException ex)
        {
            ex.AddToModelState(ViewData.ModelState);
        }

        return View(model);
    } 

when I return to the People/Me page, that would only redirect to one of the pages.

Upvotes: 0

Views: 110

Answers (1)

Diego Cardozo
Diego Cardozo

Reputation: 261

You can use Request.UrlReferrer Property. Be aware that in can be spoofed quite easily. The best way to do this is to store the previous page on the current user's session, or you can hide the previous URL in the ViewModel as explanied here.

I hope this helps, good luck!

Upvotes: 1

Related Questions