Solved

ASP.NET MVC - Changing Culture

Posted on 2010-08-24
6
1,493 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

8 Experts available now in Live!

Get 1:1 Help Now