Пример #1
0
        /// <summary>
        /// 用指定的用户控件以及视图数据呈现结果(HTML),
        /// 并生成一段代码,用于将生成的HTML替换哪个DOM节点,
        /// 然后将所有产生的HTML代码写入HttpContext.Current.Response
        /// 用户控件应从MyUserControlView&lt;T&gt;继承
        /// </summary>
        /// <param name="ucVirtualPath">用户控件的虚拟路径</param>
        /// <param name="model">视图数据</param>
        /// <param name="targetDomId">需要将输出内容替换哪个DOM节点的内容</param>
        /// <param name="flush">是否需要在输出html后调用Response.Flush()</param>
        public static void WriteUserControl(string ucVirtualPath, object model, string targetDomId, bool flush)
        {
            HttpContext context = HttpContext.Current;

            if (context == null)
            {
                return;
            }

            SetResponseContentType(context.Response);

            string html = UcExecutor.Render(ucVirtualPath, model);

            string tempId = "div-" + Guid.NewGuid().ToString();

            context.Response.Write(string.Format("<div id=\"{0}\" style=\"display: none\">", tempId));

            context.Response.Write(html);

            context.Response.Write(string.Format("</div><script type=\"text/javascript\">document.getElementById(\"{0}\").innerHTML = document.getElementById(\"{1}\").innerHTML;</script>",
                                                 targetDomId, tempId));

            if (flush)
            {
                context.Response.Flush();
            }
        }
Пример #2
0
        void IActionResult.Ouput(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            string html = UcExecutor.Render(VirtualPath, Model);

            context.Response.Write(html);
        }
Пример #3
0
        /// <summary>
        /// 用指定的用户控件以及视图数据呈现结果(HTML),
        /// 然后将产生的HTML代码写入HttpContext.Current.Response
        /// 用户控件应从MyUserControlView&lt;T&gt;继承
        /// </summary>
        /// <param name="ucVirtualPath">用户控件的虚拟路径</param>
        /// <param name="model">视图数据</param>
        /// <param name="flush">是否需要在输出html后调用Response.Flush()</param>
        public static void WriteUserControl(string ucVirtualPath, object model, bool flush)
        {
            HttpContext context = HttpContext.Current;

            if (context == null)
            {
                return;
            }

            string html = UcExecutor.Render(ucVirtualPath, model);

            WriteHtml(html, flush);
        }