returning a view with ajax


I have this problem: I have an ajax call to a controller like this:

            $('.flagsdiv').click(function () {
                var id = $(this).attr('id');
                var flag = document.getElementById('callus');
                var lang = id;
                var url = '/Home/SetCulture' + '?id=' + lang;
                flag.src = "../images/" + lang + ".gif";
                    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

                cookie = new HttpCookie("_culture");
                cookie.Value = culture;
                cookie.Expires = DateTime.Now.AddYears(1);

            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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Najam UddinCommented:
Your ajax request is completed when it get redirect result, how to handle subsequent call is on you. Register a call back in ajax and check if result has redirectURL, once this you get this response fire another ajax call for the redirectedURL.

function(result) {
    if (result.redirectUrl != null) {
        //another ajax call

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RTSolAuthor Commented:
Thanks for the hint.

I changed my aiax a bit:
                    type: "GET",
                    url: url,
                    data: {},
                    dataType: "text",
                    success: function(data) {
                        document.getElementById("contbox").style.display = "none";
                        window.location.href = window.location;

Open in new window

and now it works fine.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.