Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.NET MVC - Changing Culture

Posted on 2010-08-24
6
Medium Priority
?
1,524 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 750 total points
ID: 33512856
There is a response.redirect(HTTPREFERRER) in aspclassic, I would assume they did not remove that
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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.
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

596 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