RTSol
asked on
returning a view with ajax
Hi,
I have this problem: I have an ajax call to a controller like this:
The controller action is like this:
This executes this code in the controller
but the Index view is not returned as it should.
What can be the problem?
Best regards
RTSOL
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";
});
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");
}
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();
}
but the Index view is not returned as it should.
What can be the problem?
Best regards
RTSOL
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I changed my aiax a bit:
Open in new window
and now it works fine.
Thanks