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 7658171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:10:01+00:00 2026-05-31T13:10:01+00:00

Im trying to do an ajax call to login using credentials entered into a

  • 0

Im trying to do an ajax call to login using credentials entered into a jquery ui dialog.

The ajax call properly logs the user and successfully reaches the return RedirectToAction(“Index”, “Home”) call. However the user does not immediately see that they are logged in. I have to refresh the page for the _LoginPartial status bar to switch from Register/Login to Username/Logout.

I would think the RedirectToAction(“Index”, “Home”) call would refresh the page.
I tried to switch it to RedirectToAction(“Index”, “Some other page”) and although it runs through the action method specified is does not redirect to that page.

Here is the ajax call:

          $.ajax({
                            url: "/Account/Login",
                            type: "POST",
                            data: JSON.stringify($('#loginForm').serializeObject()),
                            dataType: 'json',
                            contentType: "application/json; charset=utf-8",
                            complete: function () {
                                $('.dialogContainer').dialog("close");
                            }
                        });

controller:

    [HttpPost]
    public ActionResult Login(LoginModel model, string returnUrl)
    {

        if (ModelState.IsValid)
        {
            if (Membership.ValidateUser(model.UserName, model.Password))
            {
                FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                if (Url.IsLocalUrl(returnUrl))
                {
                    return Redirect(returnUrl);
                }
                else
                {
                    return RedirectToAction("Index", "Home");
                }
            }
            else
            {
                ModelState.AddModelError("", "The user name or password provided is incorrect.");
            }
        }

        // If we got this far, something failed, redisplay form
        return View(model);
    }
  • 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-31T13:10:02+00:00Added an answer on May 31, 2026 at 1:10 pm

    RedirectToAction does not work when doing an Ajax call. For the same reason the ajax call does not cause a page refresh, so too does your RedirecToAction not cause the page to redirect. You are redirecting the Ajax request, not the page.

    You will have to return some kind of indicator of success to your ajax call and have your ajax call redirect the page.

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

Sidebar

Related Questions

I am trying to pass a dataString to to an ajax call using JQuery.
I trying to make my first AJAX with JSON call using jQuery and CodeIgniter.
I'm trying to make an ajax call to grab session data to insert into
I am trying to perform a nested AJAX call using the following code. The
So I am trying to use jQuery to insert data from an ajax call.
I trying to call 2 functions in the same page to submit jquery-ajax at
I am trying to call a servlet from jQuery's .ajax() function. At the moment
Im trying some ajax call with Struts2 and the JQuery library. This is the
I'm trying to do a jQuery AJAX call to my MVC controller in my
I'm trying to callback into my ViewResult Index() controller action from an ajax call

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.