In MVC it is common to display some index view from which other actions are called, e.g. "Edit". In most cases a "Back" button is simple to code since we know where we want to go back to, i.e., the Index action.
However, there are scenarios where some "Edit" action may be called from a number of places. Now, we don't know where to go back to.
I've tried various ways of passing a returnUrl parameter to actions (e.g. HtmlHelpers that add the current RawUrl as a parameter to be processed at the called action) but they always seem to have some flaw. You end up needing to keep track of whether a call to an action was from Ajax for example.
Has anyone found a simple, workable solution? I've posted mine below
I created an action attribute to adorn only certain actions such as "Index". This simply stores the current, rawUrl in session
In my breadcrumb partial view I look for the return URL in session and check if it is the current action. If not, a return URL is displayed (We don't return to the action we are already on).
The return link
Within an action I can also look up the session value and return after performing an edit for example.