当前位置: 首页>>代码示例>>C#>>正文


C# ActionResult.ExecuteResult方法代码示例

本文整理汇总了C#中System.Web.Mvc.ActionResult.ExecuteResult方法的典型用法代码示例。如果您正苦于以下问题:C# ActionResult.ExecuteResult方法的具体用法?C# ActionResult.ExecuteResult怎么用?C# ActionResult.ExecuteResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Mvc.ActionResult的用法示例。


在下文中一共展示了ActionResult.ExecuteResult方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderActionResultToString

        /// <summary>
        /// Renders an action result to a string. This is done by creating a fake http context
        /// and response objects and have that response send the data to a string builder
        /// instead of the browser.
        /// </summary>
        /// <param name="result">The action result to be rendered to string.</param>
        /// <returns>The data rendered by the given action result.</returns>
        protected string RenderActionResultToString(ActionResult result)
        {
            // Create memory writer.
            var sb = new StringBuilder();
            var memWriter = new StringWriter(sb);

            // Create fake http context to render the view.
            var fakeResponse = new HttpResponse(memWriter);
            var fakeContext = new HttpContext(System.Web.HttpContext.Current.Request, fakeResponse);
            var fakeControllerContext = new ControllerContext(
                new HttpContextWrapper(fakeContext),
                this.ControllerContext.RouteData,
                this.ControllerContext.Controller);
            var oldContext = System.Web.HttpContext.Current;
            System.Web.HttpContext.Current = fakeContext;

            // Render the view.
            result.ExecuteResult(fakeControllerContext);

            // Restore data.
            System.Web.HttpContext.Current = oldContext;

            // Flush memory and return output.
            memWriter.Flush();
            return sb.ToString();
        }
开发者ID:ganeshkumar-m,项目名称:PaulSchool,代码行数:33,代码来源:PdfController.cs

示例2: InvokeActionResultWithFilters

 protected override ResultExecutedContext InvokeActionResultWithFilters(ControllerContext controllerContext, IList<IResultFilter> filters, ActionResult actionResult)
 {
     if (actionResult is AsyncResult)
       {
     actionResult.ExecuteResult(controllerContext);
     return null;
       }
       return base.InvokeActionResultWithFilters(controllerContext, filters, actionResult);
 }
开发者ID:benlovell,项目名称:machine,代码行数:9,代码来源:AsyncActionInvoker.cs

示例3: ExecuteResult

        public static string ExecuteResult(ControllerContext controllerContext, ActionResult actionResult)
        {
            if (IsExclusiveResult(actionResult))
            {
                ExecuteExclusiveResult(controllerContext, actionResult);
                return string.Empty;
            }
            else
            {
                using (StringWriter textWriter = new StringWriter())
                {
                    controllerContext.HttpContext = new ActionResultExecutorHttpContext(controllerContext.HttpContext);
                    ((ActionResultExecutorHttpResponse)controllerContext.HttpContext.Response).Output = textWriter;
                    actionResult.ExecuteResult(controllerContext);
                    //reset HttpContext
                    controllerContext.HttpContext = null;

                    return textWriter.ToString();
                }
            }
        }
开发者ID:eyouyou,项目名称:Bsc,代码行数:21,代码来源:ModuleActionResultExecutor.cs

示例4: ToXml

        private static string ToXml(ActionResult result, ControllerContext context)
        {
            // Create memory writer.
            var sb = new StringBuilder();
            var memWriter = new StringWriter(sb);

            // Create fake http context to render the view.
            var fakeResponse = new HttpResponse(memWriter);
            var fakeContext = new HttpContext(HttpContext.Current.Request, fakeResponse);
            var fakeControllerContext = new ControllerContext(new HttpContextWrapper(fakeContext), context.RouteData, context.Controller);
            var oldContext = HttpContext.Current;
            HttpContext.Current = fakeContext;

            // Render the view.
            result.ExecuteResult(fakeControllerContext);

            // Restore old context.
            HttpContext.Current = oldContext;

            // Flush memory and return output.
            memWriter.Flush();
            return sb.ToString();
        }
开发者ID:Fiip,项目名称:DeathFolder,代码行数:23,代码来源:PDF.cs

示例5: Execute

        /// <summary>
        /// Executes the given <see cref="ActionResult"/>.
        /// </summary>
        /// <param name="actionResult">The action result to execute.</param>
        /// <returns>The result of executing the action result.</returns>
        public virtual string Execute(ActionResult actionResult)
        {
            if (actionResult == null)
            throw new ArgumentNullException("actionResult");

              // Build a new ControllerContext, using a StringWriter to capture the result of executing the ActionResult.
              using (var writer = new StringWriter(CultureInfo.InvariantCulture))
              {
            var response = new HttpResponse(writer);
            var context = new HttpContext(_controllerContext.HttpContext.ApplicationInstance.Request, response);
            var controllerContext = new ControllerContext(new HttpContextWrapper(context), _controllerContext.RouteData, _controllerContext.Controller);

            var oldContext = HttpContext.Current;
            HttpContext.Current = context;

            actionResult.ExecuteResult(controllerContext);

            HttpContext.Current = oldContext;

            writer.Flush();

            return writer.ToString();
              }
        }
开发者ID:jackleitch,项目名称:taconite-mvc,代码行数:29,代码来源:ActionResultExecutor.cs

示例6: InvokeActionResult

 protected virtual void InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
 {
     actionResult.ExecuteResult(controllerContext);
 }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:4,代码来源:ControllerActionInvoker.cs

示例7: Flush

 public static void Flush(this ControllerBase controller, ActionResult result)
 {
     result.ExecuteResult(controller.ControllerContext);
     controller.ControllerContext.HttpContext.Response.Flush();
 }
开发者ID:nikmd23,项目名称:CourtesyFlush,代码行数:5,代码来源:ContollerBaseExtension.cs


注:本文中的System.Web.Mvc.ActionResult.ExecuteResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。