title: Server side redirection after jquery ajax call in asp.net mvc 4
body: <p>I am sending login information from a jQuery AJAX call to an MVC 4 controller:</p>
  
  <pre><code>   $.post(url, data, function (response) {
        if (response=='InvalidLogin') {
            //show invalid login
        }
        else if (response == 'Error') {
            //show error
        }
        else {
            //redirecting to main page from here for the time being.
            window.location.replace("http://localhost:1378/Dashboard/Index");
        }
     });
  </code></pre>
  
  <p>If the login is successful, I want to redirect a user from the server-side to the appropriate page on the basis of user type. If the login fails, a string is sent back to user:</p>
  
  <pre><code>    [HttpPost]
      public ActionResult Index(LoginModel loginData)
      {
          if (login fails)
          {
              return Json("InvalidLogin", JsonRequestBehavior.AllowGet);
          }
          else
          {
               // I want to redirect to another controller, view, or action depending
               // on user type.
          }
      }
  </code></pre>
  
  <p>But there are problems:</p>
  
  <ol>
  <li><p>If this method returns 'ActionResult', then I'm getting the error <code>not all code paths return a value</code>.</p></li>
  <li><p>If I use 'void', I cannot return anything.</p></li>
  <li><p>Even if I use 'void' with no return, I am failing to redirect to other controller or view due to asynchronous nature of jQuery AJAX calls.</p></li>
  </ol>
  
  <p>Are there any techniques to handle such scenarios?</p>