Ejemplo n.º 1
0
        /// <summary>
        /// 执行动作结果
        /// </summary>
        /// <param name="context"></param>
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var viewData = ViewData ?? new ViewDataDictionary();

            viewData.GetModel = GetModel;

            var viewContext = ViewContext.CreateViewContext(context, viewData, TempData);

            viewContext.TemplatePath = VirtualPath;
            context.HttpContext.Response.ContentType = "text/html";
            TemplateViewExecutor.UCCacheRender(viewContext);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 用指定的用户控件以及视图数据呈现结果(HTML),
        /// 然后将产生的HTML代码写入HttpContext.Current.Response
        /// 用户控件应从ViewUserControlBase&lt;T&gt;继承
        /// </summary>
        /// <param name="context"></param>
        /// <param name="ucVirtualPath"></param>
        /// <param name="getModel"></param>
        /// <param name="flush"></param>
        public static void WriteCacheUserControl(this ControllerBase controller, string ucVirtualPath, Func <object> getModel, bool flush)
        {
            var context = controller.ControllerContext;

            if (context.HttpContext == null)
            {
                return;
            }

            var viewcontext = ViewContext.CreateViewContext(context, getModel);

            viewcontext.TemplatePath = ucVirtualPath;

            TemplateViewExecutor.UCCacheRender(viewcontext);
            if (flush)
            {
                context.HttpContext.Response.Flush();
            }
        }