本文整理汇总了C#中System.Web.Mvc.ControllerContext.RenderViewResultAsString方法的典型用法代码示例。如果您正苦于以下问题:C# ControllerContext.RenderViewResultAsString方法的具体用法?C# ControllerContext.RenderViewResultAsString怎么用?C# ControllerContext.RenderViewResultAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.ControllerContext
的用法示例。
在下文中一共展示了ControllerContext.RenderViewResultAsString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMacroStringOutput
/// <summary>
/// Renders/executes the provided macro ActionResult.
/// </summary>
/// <remarks>Macro rendering time is traced.</remarks>
private static string GetMacroStringOutput(string macroAlias, ActionResult ar, ControllerContext currentControllerContext)
{
using (DisposableTimer.Start(timer =>
LogHelper.TraceIfEnabled<MacroRenderer>("GetMacroStringOutput for {0} took {1}ms", () => macroAlias, () => timer)))
{
if (ar is ViewResultBase)
{
var viewResult = (ViewResultBase)ar;
return currentControllerContext.RenderViewResultAsString(viewResult);
}
if (ar is ContentResult)
{
var contentResult = (ContentResult)ar;
return contentResult.Content;
}
throw new NotSupportedException("Its not possible to retreive the output of a macro that doesn't return a ViewResultBase");
}
}
示例2: RenderMacroAsString
/// <summary>
/// Renders the macro output as a string
/// </summary>
/// <param name="macroAlias"></param>
/// <param name="macroParams"></param>
/// <param name="currentControllerContext"></param>
/// <param name="isForRichTextEditor">If the request is to render the contents in the back office rich text editor</param>
/// <param name="resolveContent"></param>
/// <returns></returns>
public string RenderMacroAsString(
string macroAlias,
IDictionary<string, string> macroParams,
ControllerContext currentControllerContext,
bool isForRichTextEditor,
Func<Content> resolveContent)
{
//method to get the string output of the ActionResult
Func<ActionResult, string> getStringOutput = ar =>
{
if (ar is ViewResultBase)
{
var viewResult = (ViewResultBase)ar;
return currentControllerContext.RenderViewResultAsString(viewResult);
}
if (ar is ContentResult)
{
var contentResult = (ContentResult)ar;
return contentResult.Content;
}
throw new NotSupportedException("Its not possible to retreive the output of a macro that doesn't return a ViewResultBase");
};
if (isForRichTextEditor)
{
return getStringOutput(RenderMacro(macroAlias, macroParams, currentControllerContext, true, resolveContent));
}
//if we not rendering for the rich text editor then check if we've cached this in the ScopedCache first,
//even though we are caching some macros in application cache, we're only caching the ActionResult and not the text
//output which still requires a tiny amount of processing, so we'll store all equal macro string output in ScopedCache too,
//as this will speed things regardless of whehter macros are cached or not if there's a few of the same ones per page
return _applicationContext.FrameworkContext
.ScopedCache.GetOrCreate("umb-macro-" + macroAlias + macroParams.GetHashCode(),
() => getStringOutput(RenderMacro(macroAlias, macroParams, currentControllerContext, false, resolveContent)))
.ToString();
}