/// <summary> /// Includes the template with the specified key /// </summary> /// <param name="key">Key used to resolve a template</param> /// <param name="model">Template model</param> public async Task IncludeAsync(string key, object model = null) { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException(nameof(key)); } if (this.PageLookup == null) { throw new RazorLightException("Can't locate a page as PageLookup is not set"); } PageLookupResult pageResult = PageLookup.GetPage(key); if (pageResult.Success) { ITemplatePage page = pageResult.ViewEntry.PageFactory(); page.PageContext = new PageContext(this.PageContext.ViewBag) { Writer = this.PageContext.Writer }; if (model != null) { var modelTypeInfo = new ModelTypeInfo(model.GetType()); page.PageContext.ModelTypeInfo = modelTypeInfo; object pageModel = modelTypeInfo.CreateTemplateModel(model); page.SetModel(pageModel); } await page.ExecuteAsync(); } }
private async Task RenderPageCoreAsync(ITemplatePage page, PageContext context) { page.PageContext = context; page.IncludeFunc = async(key, model) => { ITemplatePage template = await _engine.CompileTemplateAsync(key); await _engine.RenderTemplateAsync(template, model, model?.GetType(), context.Writer, context.ViewBag); }; //_pageActivator.Activate(page, context); await page.ExecuteAsync().ConfigureAwait(false); }
private Task RenderPageCoreAsync(ITemplatePage page, PageContext context) { page.PageContext = context; page.PageLookup = this.pageLookup; return(page.ExecuteAsync()); }