示例#1
0
        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);

                    object returnValue = controllerClass.Run(component, "Run", context);

                    if (returnValue is string)
                    {
                        return((string)returnValue);
                    }

                    return(TemplateUtil.ExtractBody(component.View.Render()));
                }
                catch
                {
                    component.SkipTearDown = true;

                    throw;
                }
            }
        }
示例#2
0
        internal static ActionResult RunControllerAction(ControllerAction controllerAction)
        {
            WebAppContext.AddControllerParameters(controllerAction.Parameters);

            ControllerClass controllerClass = controllerAction.ControllerClass;

            if (!controllerClass.AllowCaching)
            {
                WebAppContext.Response.DisableCaching();
            }

            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);

                    if (returnValue is ActionResult)
                    {
                        ActionResult actionResult = (ActionResult)returnValue;

                        if (actionResult.Final)
                        {
                            controller.SkipTearDown = true;
                        }

                        return(actionResult);
                    }

                    return(new RenderViewActionResult(controller.View));
                }
                catch
                {
                    controller.SkipTearDown = true;

                    throw;
                }
            }
        }