Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a way to maintain IsAjaxRequest() across RedirectToAction?
    primarykey
    data
    text
    <p>If you don't want any context or an example of why I need this, then skip to <b>The question(s)</b> at the bottom!</p> <p>In a bid to keep things tidy I initially built my application without JavaScript. I am now attempting to add a layer of unobtrusive JavaScript on the top of it.</p> <p>In the spirit of MVC I took advantage of the easy routing and re-routing you can do with things like <code>RedirectToAction()</code>.</p> <p>Suppose I have the following URL to kick off the sign up process:</p> <blockquote> <p><a href="http://www.mysite.com/signup" rel="nofollow noreferrer">http://www.mysite.com/signup</a></p> </blockquote> <p>And suppose the sign up process is two steps long:</p> <blockquote> <p><a href="http://www.mysite.com/signup/1" rel="nofollow noreferrer">http://www.mysite.com/signup/1</a><br/> <a href="http://www.mysite.com/signup/2" rel="nofollow noreferrer">http://www.mysite.com/signup/2</a><br/></p> </blockquote> <p>And suppose I want, if JavaScript is enabled, the sign up form to appear in a dialog box like ThickBox.</p> <p>If the user leaves the sign up process at step 2, but later clicks the "sign up" button, I want this URL:</p> <blockquote> <p><a href="http://www.mysite.com/signup" rel="nofollow noreferrer">http://www.mysite.com/signup</a></p> </blockquote> <p>To perform some business logic, checking the session. If they left a previous sign up effort half way through then I want to prompt them to resume that or start over.</p> <p>I might end up with the following methods:</p> <pre><code>public ActionResult SignUp(int? step) { if(!step.HasValue) { if((bool)Session["SignUpInProgress"] == true) { return RedirectToAction("WouldYouLikeToResume"); } else { step = 1; } } ... } public ActionResult WouldYouLikeToResume() { if(Request.IsAjaxRequest()) { return View("WouldYouLikeToResumeControl"); } return View(); } </code></pre> <p>The logic in <b>WouldYouLikeToResume</b> being:</p> <ul> <li>If it's an AJAX request, only return the user control, or "partial", so that the modal popup box does not contain the master page.</li> <li>Otherwise return the normal view</li> </ul> <p>This fails, however, because once I redirect out of SignUp, <code>IsAjaxRequest()</code> becomes false.</p> <p>Obviously there are very easy ways to fix this particular redirect, but I'd like to maintain the knowledge of the Ajax request globally to resolve this issue across my site.</p> <p><b>The question(s):</b></p> <p>ASP.NET MVC is very, very extensible.</p> <p>Is it possible to intercept calls to <code>RedirectToAction</code> and inject something like "isAjaxRequest" in the parameters?</p> <p>OR</p> <p>Is there some other way I can detect, safely, that the originating call was an AJAX one?</p> <p>OR</p> <p>Am I going about this the completely wrong way?</p>
    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