gerrie-govaerts
asked on
ASP.NET MVC - Changing Culture
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("StockManagemen tCookie");
cookie.Values["culture"] = culture;
cookie.Expires = DateTime.Now.AddYears(1);
System.Web.HttpContext.Cur rent.Respo nse.Cookie s.Add(cook ie);
return RedirectToAction("Index", "Reservation");
}
}
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("StockManagemen
cookie.Values["culture"] = culture;
cookie.Expires = DateTime.Now.AddYears(1);
System.Web.HttpContext.Cur
return RedirectToAction("Index", "Reservation");
}
}
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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("StockManagemen tCookie");
cookie.Values["culture"] = culture;
cookie.Expires = DateTime.Now.AddYears(1);
System.Web.HttpContext.Cur rent.Respo nse.Cookie s.Add(cook ie);
string returnUrl = Request.UrlReferrer.ToString(); return Redirect(returnUrl);
}
Thx !!!
The actual way to do it in MVC is as follows:
public ActionResult ChangeLanguage(string culture)
{
HttpCookie cookie = new HttpCookie("StockManagemen
cookie.Values["culture"] = culture;
cookie.Expires = DateTime.Now.AddYears(1);
System.Web.HttpContext.Cur
string returnUrl = Request.UrlReferrer.ToString(); return Redirect(returnUrl);
}
Thx !!!
ASKER
The comment gave me a good hint to search for.
Glad I could help
I have an MVC .NET question here, maybe you know the answer?
https://www.experts-exchange.com/questions/26427232/VS2010-MVC2.html?cid=1575&anchorAnswerId=33518074#a33518074
I have an MVC .NET question here, maybe you know the answer?
https://www.experts-exchange.com/questions/26427232/VS2010-MVC2.html?cid=1575&anchorAnswerId=33518074#a33518074
http://stackoverflow.com/questions/1560796/set-culture-in-an-asp-net-mvc-app
http://forums.asp.net/p/1426535/3185615.aspx
Hope this helps!!!!