title: Controller equivalent of HttpContext.Current in ASP.NET MVC
body: <p>I'd like to get access to the current executing Controller so I can offload the return of the appropriate ActionResult onto a helper method.  To this end, I'm looking for the equivalent of what I would have thought would be ControllerContext.Current but isn't.  Thanks!</p>
  
  <p><strong>Edit for clarification:</strong> I've got a generic form control which is JavaScript-based but I'd like to add an option so that it works with noscript.  At the moment my Controller sets the ViewData.Model to a JSON-ified Models.FormResponse&lt;T&gt;.</p>
  
  <p>This FormReponse is set up with the status of the post and any error messages that were generated, so I'd like a GetActionResult() method which does the script/noscript check (a hidden form input) and either:</p>
  
  <ol>
  <li>Sets the Model to the JSONed FormResponse and returns a View(), or</li>
  <li>Serializes the FormResponse to the Session and returns a Redirect().</li>
  </ol>
  
  <p>As this obviously changes the return value and I don't want to do the check myself every time, I need to call View or Redirect from the FormResponse's GetActionResult method in order to call this as:</p>
  
  <pre><code>return formResponse.GetActionResult();
  </code></pre>
  
  <p>I know with a more astronautical design this could be made even more robust but as the noscript option is not a major feature at the moment, I just need to get a quick solution working that doesn't break other things.</p>
  
  <p><strong>Update #2</strong></p>
  
  <p>The following, implemented in an ActionResult class, does the job for me.  Thanks CVertex!</p>
  
  <pre><code>public override void ExecuteResult(ControllerContext context)
      {
          if (CMSEnvironment.NoScript)
          {
              Oracle.Response.Redirect(Oracle.Request.UrlReferrer.ToString(), true);
          }
  
          context.Controller.ViewData.Model = _model.ToJSON();
  
          new ViewResult()
          {
              ViewName = Areas.Site.Helpers.SharedView.Service,
              ViewData = context.Controller.ViewData
          }.ExecuteResult(context);
      }
  </code></pre>