예제 #1
0
        public static async Task <HtmlString> RenderViewAsync(this TabbedContent tab, string viewName, HttpContext context, ITempDataDictionary tempDataDictionary)
        {
            using (var writer = new StringWriter())
            {
                IViewEngine      viewEngine    = context.RequestServices.GetService(typeof(ICompositeViewEngine)) as ICompositeViewEngine;
                var              actionContext = new ActionContext(context, new Microsoft.AspNetCore.Routing.RouteData(), new ActionDescriptor());
                ViewEngineResult viewResult    = viewEngine.GetView(viewName, viewName, false);

                if (viewResult.Success == false)
                {
                    return(new HtmlString(""));
                    //return $"A view with the name {viewName} could not be found";
                }

                var viewDictionary =
                    new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary());

                ViewContext viewContext = new ViewContext(
                    actionContext,
                    viewResult.View,
                    viewDictionary,
                    tempDataDictionary,
                    writer,
                    new HtmlHelperOptions()
                    );

                await viewResult.View.RenderAsync(viewContext);

                return(new HtmlString(writer.GetStringBuilder().ToString()));
            }
        }
        private void AddTabbedContent(PageRoot cmsContent, Page <Article> model)
        {
            if (cmsContent.Article?.TabbedContents == null)
            {
                return;
            }

            var tabbedContents = new List <TabbedContent>();

            foreach (var responseTabbedContent in cmsContent.Article.TabbedContents)
            {
                var content = new TabbedContent
                {
                    TabName         = responseTabbedContent.TabName,
                    TabTitle        = responseTabbedContent.TabTitle,
                    FindTraineeShip = responseTabbedContent.FindTraineeship
                };

                var pageContent = new List <IHtmlControl>();

                foreach (var tabContent in responseTabbedContent.Content.Items)
                {
                    var factory = _controlAbstractFactory.CreateControlFactoryFor(tabContent);

                    if (factory == null)
                    {
                        continue;
                    }

                    pageContent.Add(factory.Create(tabContent));
                }

                content.Content = pageContent;
                tabbedContents.Add(content);
            }

            model.Content.TabbedContents = tabbedContents;
        }