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


C# ControllerContext.RenderViewResultAsString方法代码示例

本文整理汇总了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");
            }
        }
开发者ID:paulsuart,项目名称:rebelcmsxu5,代码行数:23,代码来源:MacroRenderer.cs

示例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();
        }
开发者ID:Joebeazelman,项目名称:rebelcmsxu5,代码行数:48,代码来源:MacroRenderer.cs


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