Solved

ASP.NET MVC - Changing Culture

Posted on 2010-08-24
6
1,497 Views
Last Modified: 2013-11-08
Hello

I'm trying to change the displayed language in my MVC application by routing the ActionLink on my Masterpage to an action on a controller. However, I would like that the page I'm on refreshed itself with the changed culture.

Now I'm hardcoding to have a RedirectToAction back to the Index action of another controller.

Is is possible to return to the same page?

Here is my code:

    public class CultureController : Controller
    {
        public ActionResult ChangeLanguage(string culture)
        {
            HttpCookie cookie = new HttpCookie("StockManagementCookie");
            cookie.Values["culture"] = culture;
            cookie.Expires = DateTime.Now.AddYears(1);
            System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
            return RedirectToAction("Index", "Reservation");
        }
    }
0
Comment
Question by:gerrie-govaerts
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:Dhanasekaran Sengodan
ID: 33508740
0
 

Author Comment

by:gerrie-govaerts
ID: 33508784
I'm sorry but both links do not refer to the problem I have talked about.

The problem is: instead of using hard coded RedirectToAction variables like Index + Reservation, I want to use the controller and action that have invoked the language change, so that I can redirect to it, as if the page has been refreshed, but now with another display language.
0
 
LVL 9

Accepted Solution

by:
rg20 earned 250 total points
ID: 33512856
There is a response.redirect(HTTPREFERRER) in aspclassic, I would assume they did not remove that
0
Give your grad a cloud of their own!

With up to 8TB of storage, give your favorite graduate their own personal cloud to centralize all their photos, videos and music in one safe place. They can save, sync and share all their stuff, and automatic photo backup helps free up space on their smartphone and tablet.

 

Author Comment

by:gerrie-govaerts
ID: 33518599
Thanks for the comment rq20, it already gave me a good hint.

The actual way to do it in MVC is as follows:

                public ActionResult ChangeLanguage(string culture)
        {
            HttpCookie cookie = new HttpCookie("StockManagementCookie");
            cookie.Values["culture"] = culture;
            cookie.Expires = DateTime.Now.AddYears(1);
            System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
            string returnUrl = Request.UrlReferrer.ToString();            return Redirect(returnUrl);
        }


Thx !!!
0
 

Author Closing Comment

by:gerrie-govaerts
ID: 33518603
The comment gave me a good hint to search for.
0
 
LVL 9

Expert Comment

by:rg20
ID: 33520882
Glad I could help

I have an MVC .NET question here, maybe you know the answer?

http://www.experts-exchange.com/Web_Development/Web_Frameworks/MVC/Q_26427232.html?cid=1575#a33518074
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
crm development 2 65
Multiple file Upload asp.net 2 38
How to access a DataBinder.Eval variable using C# ? 4 27
Please explain "Multi-Tenant Services" 5 62
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
A short film showing how OnPage and Connectwise integration works.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now