I have a shared page in my ASP.NET MVC app that can be accessed from several different pages in my app. If I want the user to return to their original page after they have done their business on the shared page, what’s the best way to figure out where the user was, and tell the app to go there?
Note that I’m currently doing this for the Cancel button on the shared page by telling onclick to use the page history:
<input type="button" value="Cancel" onclick="if (history.length == 0) { window.location='<%=Url.Action("Index", "Home") %>' } else { history.back() }" />
but this won’t work for Save if the shared page updates data displayed on the original page.
Two ways I can think of are to store the url of the calling page in a hidden input element or as a argument in the current page’s address. Both of these will survive refreshes or several steps of navigation, you just have to make sure that the variables are passed on to the next page.