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.
How can I overcome this problem?
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.
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.