I am using MVC 3 with Razor Engine.
I’m trying to implement an actionlink in the layout page that will change the language of the page and redirect me back to the page that called the event.
So my question is how can I handle layout actions and know which url the actionlink was called from.
public void Changelanguage()
{
if (MyClass.CommonFuncs.CheckLang() == "en-US")
{
MyClass.CommonFuncs.SetArabicLang();
}
else
{
MyClass.CommonFuncs.SetEnglishLang();
}
this.Redirect(Request.UrlReferrer.AbsoluteUri);
}
You would have to detect the page to redirect back to who redirected to that page originally using the Request.UrlReferrer on the HttpContext:
http://msdn.microsoft.com/en-us/library/system.web.httprequest.urlreferrer.aspx
Or, pass the original page in the URL when you change the language, and use that URL to redirect back to.