Solved

ASP.NET MVC - Changing Culture

Posted on 2010-08-24
6
1,503 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 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