當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。