title: MVC extending controller to have ajax-aware Redirect functionality
body: <p>Hi I am learning Ajax + MVC. I figured it would be nice for the Controller to automatically handle ajax-aware Redirect(). After some digging, I found the code from this <a href="http://craftycodeblog.com/2010/05/15/asp-net-mvc-ajax-redirect/" rel="nofollow">link</a>. The code below is totally transparent to user, a user can just call Redirect(someUrlString) without needing to worry about difference between normal/ajax calls. Makes it very neat and cool. </p>
  
  <pre><code>public abstract class BaseController : System.Web.Mvc.Controller {
      //turn into ajax aware redirect
      protected override RedirectResult Redirect(string url) {
          return new AjaxAwareRedirectResult(url);
      }
  }
  </code></pre>
  
  <p>and ...</p>
  
  <pre><code>public class AjaxAwareRedirectResult : RedirectResult {
      public AjaxAwareRedirectResult(string url) : base(url) { }
      public override void ExecuteResult(ControllerContext context) {
          if (context.RequestContext.HttpContext.Request.IsAjaxRequest()) {
              string desturl = UrlHelper.GenerateContentUrl(Url, context.HttpContext);
              JavaScriptResult result = new JavaScriptResult() { 
                                        Script = "window.location='" + desturl + "';" };
              result.ExecuteResult(context);
          }
          else { base.ExecuteResult(context); }
      }
  }
  </code></pre>
  
  <p>However, it is not complete. Challenge is: </p>
  
  <p><em>RedirectToRouteResult</em> <strong><code>RedirectToAction</code></strong>(<em>ActionResult</em> result) </p>
  
  <p>is not there yet (Very handy especially for T4MVC). </p>
  
  <p>As I am still new to MVC, I tried, but I am not knowledgeable enough to sufficiently figure out how to write this myself. Could any of you experts please help me with this? so I can learn it from your code? Thank you very much.</p>