tags:

views:

54

answers:

2

I have a form on all my pages that allows the user to select their language. After this action completes I change the current language for that user then I need to make sure I redirect to the same action they were on previously.

I am not sure what the best approach is to do this in asp.net mvc. One approach is that on every page I save the controller and action as hidden variables in the language form.

The other would to save the last controller and action into tempdata and then referencing it in the action that sets the current language.

Any thoughts on which approach or another that is best for this scenario?

+1  A: 

The request URL of the page the forms lives on has all the necessary information about the Controller and the Action. So, if you add it as a returnurl (or simply ru) parameter to the form, you can redirect from the POST action to that URL instead of trying to find the right Controller and Action.

Franci Penov
Makes sense, I was also thinking of just redirecting to the http referrer url.
Jeff
And indeed that is the way I would recommend.
Trimack
@jeff having an ru parameter allows you to choose the page to redirect the user at POST time and can be changed by a client-side logic. using the referrer URL always redirects the user back to the page that initiated the POST.
Franci Penov
A: 

You can also refer the demo available at http://karticles.blogspot.com/2009/12/aspnet-mvc-pattern-var-controllersview.html