internal static string RunViewComponent(ControllerAction controllerAction, TemplateParserContext context) { ControllerClass controllerClass = controllerAction.ControllerClass; if (!controllerClass.IsActionMethod(controllerAction.ActionMethod)) { return(null); } using (ViewComponent component = controllerClass.CreateViewComponent(context)) { try { controllerClass.SetupController(component, context); string returnValue = controllerClass.Run(component, "Run", context) as string; if (returnValue != null) { return(returnValue); } return(TemplateUtil.ExtractBody(component.View.Render())); } catch { component.SkipTearDown = true; throw; } } }
internal static ActionResult RunControllerAction(ControllerAction controllerAction) { WebAppContext.AddControllerParameters(controllerAction.Parameters); ControllerClass controllerClass = controllerAction.ControllerClass; if (!controllerClass.IsActionMethod(controllerAction.ActionMethod)) { return(null); } using (Controller controller = controllerClass.CreateController()) // Dispose() will call [AfterAction] methods { try { WebAppContext.RootView = controller.View; controllerClass.SetupController(controller, null); object returnValue = controllerClass.Run(controller, controllerAction.ActionMethod, null); var actionResult = returnValue as ActionResult; if (actionResult != null) { if (actionResult.Final) { controller.SkipTearDown = true; } return(actionResult); } return(new RenderViewActionResult(controller.View)); } catch { controller.SkipTearDown = true; throw; } } }