ASP.NET MVC3: Back button not working

710 views Asked by At

So I'm using MVC3 and I am aware of the following code to return back to the original page. The location that the user was previously on.

<input type="button" class="cancel" value="Back" onclick="location.href='@Request.UrlReferrer.ToString()'"/>

So I have a Submit button, and a cancel button as above..

The problem is that when a submit fails, and is caught using server side validation.. The page it has now come from.. is itself!

So the cancel button seizes to function as expected, as it is merely refreshing the page.

  1. How can I overcome this problem?

  2. Is there an easy way to pass search url through the view then edit page so that I can get back to it after navigating a few pages? Without having to create and submit params on each page.

1

There are 1 answers

1
Erik Funkenbusch On BEST ANSWER

The code you're using isn't reliable. You can't 100% guarantee it will always work. You're going to have situations like this one.

There are solutions, but they're clunky and a pain. It's better to simply design your site so they are not needed. For instance, you can pass a return url as a querystring.