Exemple #1
0
        /// <summary>
        /// 序列化异步 HtmlPart,实现浏览器动态解析并加载,且不需要使用 Ajax。
        /// </summary>
        /// <param name="part"></param>
        /// <returns></returns>
        public static string SerializeAsyncPart(HtmlPart part)
        {
            var obj = new {
                id = part.ID,
                content = part.ToString()
            };

            var json = JsonConvert.SerializeObject(obj);

            var js = "<script>showPart(" + json + ")</script>";
            return js;
        }
 /// <summary>
 /// 创建 HtmlResponse 的新实例。
 /// </summary>
 public HtmlResponse()
 {
     Parts = new HtmlPart[0];
     ContentType = "text/html; charset=utf-8";
     UseBigPipe = true;
 }
 public override Task PrepareStreamAsync()
 {
     return Task.Run(() => {
         content = GetRawCallback();
     });
 }
 private void writePart(Stream s, HtmlPart part, HtmlOutputFormat format)
 {
     if (UseBigPipe) {
         var c = HttpUtil.SerializeAsyncPart(part);
         s.Write(c, true);
     }
     else {
         (new HtmlElement("div") { ID = part.ID, InnerHtml = part }).WriteToStream(s, format, 4);
         s.Flush();
     }
 }