/// <summary> /// Parses a template with a given <paramref name="key" /> /// </summary> /// <param name="key">Key used to resolve a template</param> /// <param name="model">Template model</param> /// <param name="modelType">Type of the model</param> /// <param name="viewBag">Dynamic ViewBag (can be null)</param> /// <returns>Returns parsed string</returns> /// <remarks>Result is stored in cache</remarks> public string Parse(string key, object model, Type modelType, ExpandoObject viewBag) { PageLookupResult result = pageLookup.GetPage(key); if (!result.Success) { throw new RazorLightException($"Can't find a view with a specified key ({key})"); } var pageContext = new PageContext(viewBag) { ModelTypeInfo = new ModelTypeInfo(modelType) }; foreach (var viewStartPage in result.ViewStartEntries) { pageContext.ViewStartPages.Add(viewStartPage.PageFactory()); } TemplatePage page = result.ViewEntry.PageFactory(); page.PageContext = pageContext; return(RunTemplate(page, model)); }
private TemplatePage GetLayoutPage(string layoutKey) { PageLookupResult layoutPageResult = pageLookup.GetPage(layoutKey); if (!layoutPageResult.Success) { throw new RazorLightException($"Layout cannot be located ({layoutKey})"); } TemplatePage layoutPage = layoutPageResult.ViewEntry.PageFactory(); return(layoutPage); }