Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6681737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:37:27+00:00 2026-05-26T04:37:27+00:00

I have a bilangual MVC 3 application. I use a dropdownlist to change the

  • 0

I have a bilangual MVC 3 application. I use a dropdownlist to change the language by saving the value of the dropdownlist into cookie and session. the problem is when I release it, it works only in IE. following is my code. note: the site will be reloaded and when I close firefox or chrome and reponed it, the language has been changed but nothing happend if I dont close FF or chrome. thank you very much for your help.
I have used $.get, $.post every kind of combinations.

JavaScript code:

$(function () {
    $('#languagesDiv select').change(function () {
        var myvalue = $(this).val();
        $.ajax({
            type: "POST",
            dataType: "xml",
            url: "/Language/SetLanguage",
            data: { code: myvalue },
            success: function (data) {
            },
            error: function (xhr, textStatus, errorThrown) {
            }
        });

        //             @*   $.post('@Url.Action("SetLanguage", "Language")', { code: $(this).val() },
        //                            function (result) {
        //                            }
        //                );*@

        var myDate = new Date();
        myDate.setDate(myDate.getDate() + 21);

        $.cookie('MyData', $(this).val(), { path: '/', expires: myDate });

        //window.location.reload();
        window.location.href = '/News/Index';
    });
}); 

C# code:

//tested with and without [httppost]
public void SetLanguage(string code)
{
    if (Session["MyCulture"] != null && Convert.ToString(Session["MyCulture"]) != code ) 
    {
        Session["MyCulture"] = code;
        HttpCookie aCookie = Request.Cookies["MyData"]; // new HttpCookie("MyData");
        aCookie.Value = code;
        //HttpCookie aCookie = Request.Cookies["LangCookie"];
        aCookie.Expires = System.DateTime.Now.AddDays(21);
        Response.Cookies.Add(aCookie);
        //Response.AppendCookie(aCookie);
    }

    //return RedirectToAction("Index", "News");           
}

Thank you again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:37:28+00:00Added an answer on May 26, 2026 at 4:37 am

    The problem I see (there could be others with the backend) is that your AJAX request likely won’t complete in the other/newer browsers. When you call this:

    window.location.href = '/News/Index';
    

    …you’re telling the browser to navigate away, this means it’s instantly going there, regardless of whether that previous AJAX request completed (the browser will likely kill the request early and move on).

    Instead, you should redirect after that request completes and do the re-direct in your success handler, like this:

    $(function () {
      $('#languagesDiv select').change(function () {
        var myvalue = $(this).val();
        $.ajax({
          type: "POST",
          dataType: "xml",
          url: "/Language/SetLanguage",
          data: { code: myvalue },
          success: function (data) {
            var myDate = new Date();
            myDate.setDate(myDate.getDate() + 21);    
            $.cookie('MyData', $(this).val(), { path: '/', expires: myDate });
    
            window.location.href = '/News/Index';
          }
        });
      });
    }); 
    

    This way you’re only telling the user to change pages after you’ve successfully made a request to change the language.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bilingual MVC 3 application, I use cookies and session to save
So I have a problem... I am trying to consolidate 5 or so bilingual
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
Have converted devise new session from erb to Haml but doens't work, this is
I have a bilingual website The value of a form field is set to
Have a look at one of my websites: moskah.com The problem is that it
Have one Doubt In MVC Architecture we can able to pass data from Controller
Have a xml string, goal is to replace an xml element value to a
I'm creating a bilingual site and have decided to use session_start to determine the
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.