Exemple #1
0
        public async Task <string> RenderTemplateAsync <T>(ITemplatePage templatePage, T model, IPageContext context)
        {
            TkDebug.AssertArgumentNull(templatePage, nameof(templatePage), this);
            TkDebug.AssertArgumentNull(context, nameof(context), this);

            templatePage.SetModel(model);
            context.Convert <PageContext>().Model = model;
            using (var writer = new StringWriter())
                using (var scope = new MemoryPoolViewBufferScope())
                {
                    var oldWriter = context.Writer;
                    try
                    {
                        context.Writer = writer;
                        var renderer = new TemplateRenderer(this, HtmlEncoder.Default, scope);
                        await renderer.RenderAsync(templatePage).ConfigureAwait(false);

                        return(writer.ToString());
                    }
                    finally
                    {
                        context.Writer = oldWriter;
                    }
                }
        }
Exemple #2
0
        public async Task RenderTemplateAsync <T>(ITemplatePage templatePage, T model,
                                                  TextWriter textWriter, object initData, ExpandoObject viewBag)
        {
            TkDebug.AssertArgumentNull(textWriter, nameof(textWriter), this);

            SetModelContext(templatePage, textWriter, model, initData, viewBag);

            using (var scope = new MemoryPoolViewBufferScope())
            {
                var renderer = new TemplateRenderer(this, HtmlEncoder.Default, scope);
                await renderer.RenderAsync(templatePage).ConfigureAwait(false);
            }
        }