Exemplo n.º 1
0
        public async Task <string> ViewHtmlGenerator(string viewName, HttpContextItems httpContextItems, bool partial = false)
        {
            using (StringWriter writer = new StringWriter())
            {
                IViewEngine      viewEngine = httpContextItems.ControllerContext.HttpContext.RequestServices.GetService(typeof(ICompositeViewEngine)) as ICompositeViewEngine;
                ViewEngineResult viewResult = viewEngine.FindView(httpContextItems.ActionContext, viewName, !partial);
                if (viewResult.Success == false)
                {
                    return($"A view with the name {viewName} could not be found");
                }
                await viewResult.View.RenderAsync(new ViewContext(
                                                      httpContextItems.ActionContext,
                                                      viewResult.View,
                                                      new ViewDataDictionary((IModelMetadataProvider)httpContextItems.HttpContextAccessor.HttpContext.RequestServices.GetService(typeof(IModelMetadataProvider)), httpContextItems.ActionContext.ModelState),
                                                      new TempDataDictionary(httpContextItems.DefaultHttpContext, new TempDataProvider()),
                                                      writer,
                                                      new HtmlHelperOptions()
                                                      ));

                return(writer.GetStringBuilder().ToString());
            }
        }
Exemplo n.º 2
0
        public Tuple <string, HttpContextItems> CoreItemsForRenderView(string viewName)
        {
            var httpContextItems = new HttpContextItems();

            return(new Tuple <string, HttpContextItems>(string.IsNullOrEmpty(viewName) ? httpContextItems.ControllerContext.ActionDescriptor.ActionName : viewName, httpContextItems));
        }