Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC RedirectToAction and XMLHttpRequest send
    primarykey
    data
    text
    <p>I have a form which can contain files and it shows a progress bar successfully. My problem is that in the MVC Controller I have:</p> <pre><code>return RedirectToAction("Complete", new { title = title }); </code></pre> <p>This goes and executes the Complete method if I step through but it then goes back to the JavaScript load event and does not redirect me unless I add a JavaScript redirect in the load event listener (uploadComplete):</p> <pre><code>var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", uploadProgress, false); xhr.addEventListener("load", uploadComplete, false); xhr.addEventListener("error", uploadFailed, false); xhr.addEventListener("abort", uploadCanceled, false); xhr.open("POST", "/Submit-Recipe", true); xhr.send(fd); function uploadComplete(evt) { //var valueFromController = how do I get a value here?; //window.location.replace("http://@ConfigurationManager.AppSettings["website"]/SubmitRecipeComplete/" + valueFromTheController); } </code></pre> <p>Is there a way to not have to add a JavaScript redirect? If I do need a JavaScript redirect, how can I pass a variable back from the controller when it needs to be an ActionResult (for if there is an error and I need to redisplay the page?).</p> <p>I can work around this by adding a second page where I could know the "valueFromController" but 2 forms breaks the workflow a bit.</p> <p><strong>EDIT</strong></p> <p>I did what Praveen said but GetData() did not work for me so I used this instead:</p> <pre><code>evt.currentTarget.responseText </code></pre> <p>To determine if to return the View or Content I added this just before xhr.send(fd);</p> <pre><code>xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); </code></pre> <p>In the controller I can then do:</p> <pre><code>if (Request.IsAjaxRequest()) { return Content(title); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload