title: Why do window.location and window.location.href return a Page Not Found Error in MVC?
body: <p>I have an MVC application that sends users to a shopping cart page to view the summary of their items prior to checkout. When the user clicks the checkout link, it triggers this JavaScript function:</p>
  
  <pre><code>function CartCheckOut() {
      var cartitems = '@Html.Raw(Json.Encode(Model.CartItems))';
      $.ajax({
             type: 'POST',
             datatype: "application/json",
             data: { cartitems: cartitems },
             url: '@Url.Action("CheckOut", "ShoppingCart")',
             success: function (result) {
               if (result) {
                 window.location = result;
               }
             }
      });
   }
  </code></pre>
  
  <p>Which in turn sends them to the Shopping Cart Controller that processes the request and returns a URL with a merchant key so they can be redirected to the merchants site to complete the checkout process.</p>
  
  <p>To simplify the description of the problem, I am excluding other pieces of the Checkout method but it simply returns a string URL with a key/pair value. But the resulting problem is the same irrelevant of the URL that is returned to the function as it always results in a Page not found error after landing me on the same page that launched the call.</p>
  
  <pre><code>public string CheckOut(string cartitems) 
  {
      return "http://www.google.com";
  }
  </code></pre>
  
  <p>If I use window.open(result); within the CartCheckOut function, a new page is launched and I'm taken to the URL that gets passed back from the controller.</p>
  
  <p>But if I use either</p>
  
  <pre><code>window.location = result; 
  </code></pre>
  
  <p>or </p>
  
  <pre><code>window.location.href = result;
  </code></pre>
  
  <p>I get a Page not found error with no redirection to the specified URL.
  I've also tried assigning the Controller method as an ActionResult and RedirectResult to perform a return Redirect(url) but the results are the same.</p>
  
  <p>Is this method of performing a redirect incorrect or could I be missing some critical piece?</p>