I want to access the current execution controller so that I can offload the return of the corresponding ActionResult to a helper method. To this end, I am looking for the equivalent of what I thought would be ControllerContext.Current but not. Thanks!
Edit for clarification: I have a generic JavaScript based form control, but I would like to add a parameter to make it work with noscript. My controller is currently setting ViewData.Model to JSON-ified Models.FormResponse <T>.
This FormReponse is configured with the status of the message and any error messages that were generated, so I need the GetActionResult () method, which performs a script / noscript check (entering a hidden form) and either:
- Sets the model to a JSONed FormResponse and returns View () or
- Serializes FormResponse for the session and returns Redirect ().
Since this obviously changes the return value, and I donβt want to check every time, I need to call View or Redirect from the FormResponse GetActionResult method to call it like:
return formResponse.GetActionResult();
I know that with a more astronautical design this can be made even more reliable, but since the noscript parameter is not an important feature at the moment, I just need to get a quick solution that will not break other things.
Update # 2
, ActionResult, . CVertex!
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);
}