Exemplo n.º 1
0
        protected virtual async Task RenderPartialCoreAsync([NotNull] string partialViewName,
                                                            object model,
                                                            ViewDataDictionary viewData,
                                                            TextWriter writer)
        {
            // Determine which ViewData we should use to construct a new ViewData
            var baseViewData = viewData ?? ViewData;

            var newViewData = new ViewDataDictionary(baseViewData, model);

            var viewEngineResult = _viewEngine.FindPartialView(ViewContext, partialViewName);

            if (!viewEngineResult.Success)
            {
                var locations = string.Empty;
                if (viewEngineResult.SearchedLocations != null)
                {
                    locations = Environment.NewLine +
                                string.Join(Environment.NewLine, viewEngineResult.SearchedLocations);
                }

                throw new InvalidOperationException(
                          Resources.FormatViewEngine_PartialViewNotFound(partialViewName, locations));
            }

            var view = viewEngineResult.View;

            using (view as IDisposable)
            {
                var viewContext = new ViewContext(ViewContext, view, newViewData, writer);
                await viewEngineResult.View.RenderAsync(viewContext);
            }
        }
Exemplo n.º 2
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = null;

            var partialResult = _viewEngine.FindPartialView(ViewContext, Name);

            if (partialResult != null && partialResult.Success)
            {
                var partialViewData    = new ViewDataDictionary(ViewContext.ViewData, Model);
                var partialWriter      = new TagHelperContentWrapperTextWriter(ViewContext.Writer.Encoding, output.Content);
                var partialViewContext = new ViewContext(ViewContext, partialResult.View, partialViewData, partialWriter);

                await partialResult.View.RenderAsync(partialViewContext);
            }
        }