/// <summary> /// Renders a template to the specified <paramref name="textWriter"/> /// </summary> /// <param name="templatePage">Instance of a template</param> /// <param name="model">Template model</param> /// <param name="modelType">Type of the model</param> /// <param name="viewBag">Dynamic viewBag of the page</param> /// <param name="textWriter">Output</param> public async Task RenderTemplateAsync( ITemplatePage templatePage, object model, Type modelType, TextWriter textWriter, ExpandoObject viewBag = null) { if (textWriter == null) { throw new ArgumentNullException(nameof(textWriter)); } var pageContext = new PageContext(viewBag) { ExecutingPageKey = templatePage.Key, Writer = textWriter }; if (model != null) { pageContext.ModelTypeInfo = new ModelTypeInfo(modelType); object pageModel = pageContext.ModelTypeInfo.CreateTemplateModel(model); templatePage.SetModel(pageModel); } templatePage.PageContext = pageContext; using (var renderer = new TemplateRenderer(templatePage, this, HtmlEncoder.Default)) { await renderer.RenderAsync().ConfigureAwait(false); } }
public async Task RenderIncludedTemplateAsync <T>( ITemplatePage templatePage, T model, TextWriter textWriter, ExpandoObject viewBag, TemplateRenderer templateRenderer) { SetModelContext(templatePage, textWriter, model, viewBag); await templateRenderer.RenderAsync(templatePage).ConfigureAwait(false); }
public async Task RenderIncludedTemplateAsync( ITemplatePage templatePage, object model, Type modelType, TextWriter textWriter, ExpandoObject viewBag, TemplateRenderer templateRenderer) { SetModelContext(templatePage, textWriter, model, modelType, viewBag); templateRenderer.RazorPage = templatePage; await templateRenderer.RenderAsync().ConfigureAwait(false); }
/// <summary> /// Renders a template to the specified <paramref name="textWriter"/> /// </summary> /// <param name="templatePage">Instance of a template</param> /// <param name="model">Template model</param> /// <param name="modelType">Type of the model</param> /// <param name="viewBag">Dynamic viewBag of the page</param> /// <param name="textWriter">Output</param> public async Task RenderTemplateAsync <T>( ITemplatePage templatePage, T model, TextWriter textWriter, ExpandoObject viewBag = null) { SetModelContext(templatePage, textWriter, model, viewBag); using (var scope = new MemoryPoolViewBufferScope()) { var renderer = new TemplateRenderer(templatePage, this, HtmlEncoder.Default, scope); await renderer.RenderAsync().ConfigureAwait(false); } }