本文整理汇总了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();
}
示例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);
}
示例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();
}
}
}
示例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();
}
示例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();
}
}
示例6: InvokeActionResult
protected virtual void InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
{
actionResult.ExecuteResult(controllerContext);
}
示例7: Flush
public static void Flush(this ControllerBase controller, ActionResult result)
{
result.ExecuteResult(controller.ControllerContext);
controller.ControllerContext.HttpContext.Response.Flush();
}