Hi,
I have this problem: I have an ajax call to a controller like this:
$('.flagsdiv').click(function () {
var id = $(this).attr('id');
console.log(id);
var flag = document.getElementById('callus');
var lang = id;
var url = '/Home/SetCulture' + '?id=' + lang;
flag.src = "../images/" + lang + ".gif";
console.log(url);
$.ajax({
type: "GET",
url: url,
data: {},
dataType: "text"
});
document.getElementById("contbox").style.display = "none";
});
Open in new window
The controller action is like this:
public ActionResult SetCulture(string id)
{
string culture = id;
culture = CultureHelper.GetImplementedCulture(culture);
RouteData.Values["culture"] = culture;
// Save culture in a cookie
HttpCookie cookie = Request.Cookies["_culture"];
if (cookie != null)
cookie.Value = culture; // update cookie value
else
{
cookie = new HttpCookie("_culture");
cookie.Value = culture;
cookie.Expires = DateTime.Now.AddYears(1);
}
Response.Cookies.Add(cookie);
return RedirectToAction("Index", "Home");
}
Open in new window
This executes this code in the controller
public ActionResult Index()
{
ViewBag.Message = "Welcome to Rt solutions!";
string culture = CultureHelper.GetCurrentCulture().Substring(0, 2);
ViewBag.Lang = "../images/" + culture + ".gif";
return View();
}
Open in new window
but the Index view is not returned as it should.
What can be the problem?
Best regards
RTSOL
I changed my aiax a bit:
Open in new window
and now it works fine.
Thanks