title: How to pass parameter while redirecting to Action on Ajax Success?
body: <p>I have two <code>View (Create and Completed)</code> and a <code>Controller</code>. I use <code>Ajax</code> for creating new records <code>(Create)</code> in a popup window and after the operation succeeded, I want to close the <code>Create</code> and display the returned message from the <code>Controller</code>. Although I can easily show the message on <code>Create</code> view, I cannot pass this message to <code>Completed</code> view (I want to close or hide <code>Create</code> and open <code>Completed</code> to show the message. So, could you clarify me please how to succeed this? On the other hand, is it not possible to determine if the request is an Ajax request with <code>Request.IsAjaxRequest()</code> method as shown below. Any idea?</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>[HttpPost]
  [ValidateAntiForgeryToken]
  public ActionResult Create([Bind(Exclude = null)] MyModel model)
  {  
      if (ModelState.IsValid)
      {
          //... (removed for brevity)
          TempData["message"] = "Operation succeeded.";
          var redirectUrl = new UrlHelper(Request.RequestContext).Action("Completed", "Home", new { /* params */ });
          return Json(new { success = true, message = TempData["message"], url = redirectUrl });
      }
  }
  </code></pre>
  
  <p><br/>
  <strong>View:</strong></p>
  
  <pre><code>$('form').submit(function (event) {
      event.preventDefault();
      $.ajax({
          type: "POST",
          url: '@Url.Action("Create", "Home")',
          data: formdata,
          dataType: "json",
          processData: false, 
          contentType: false, 
          success: function (response) {
             if (response.success) {
                 //I can pass id in the url, but I need to pass response.message as parameter
                 window.location.href = 'Url.Action("Completed", "Home", new { id=1 })';
              }
          }
      });
  });
  </code></pre>
  
  <p>On the other hand, the <code>Request.IsAjaxRequest()</code> in the Controller always returns true even if I make the request from another View (Create on a new page View) that is use <code>Html.BeginForm</code> instead of <code>Ajax post</code>. Is there a problem with <code>Request.IsAjaxRequest()</code> in MVC5?</p>
  
  <pre><code>if (Request.IsAjaxRequest())
  {
      //Always returns true
  }
  </code></pre>
  
  <p>Any help would be appreciated. </p>