Exemplo n.º 1
0
 protected virtual void SetViewContext(ViewContext viewContext)
 {
     _viewContext = viewContext;
     CreateHelpers();
 }
Exemplo n.º 2
0
        public void Render(ViewContext viewContext, TextWriter writer)
        {
            var wrappedViewContext = new ViewContext(
                new ControllerContext(wrappedHttpContext, viewContext.RouteData, viewContext.Controller),
                viewContext.View,
                viewContext.ViewData,
                viewContext.TempData);

            ViewData = wrappedViewContext.ViewData;
            ViewContext = wrappedViewContext;

            var outerView = ViewContext.View as SparkView;
            var isNestedView = outerView != null && ReferenceEquals(this, outerView) == false;

            var priorContent = Content;
            var priorOnce = OnceTable;
            TextWriter priorContentView = null;

            if (isNestedView)
            {
                // set aside the "view" content, to avoid modification
                if (outerView.Content.TryGetValue("view", out priorContentView))
                    outerView.Content.Remove("view");

                // assume the values of the outer view collections
                Content = outerView.Content;
                OnceTable = outerView.OnceTable;
            }

            RenderView(writer);

            if (isNestedView)
            {
                Content = priorContent;
                OnceTable = priorOnce;

                // restore previous state of "view" content
                if (priorContentView != null)
                    outerView.Content["view"] = priorContentView;
                else if (outerView.Content.ContainsKey("view"))
                    outerView.Content.Remove("view");
            }
            else
            {
                // proactively dispose named content. pools spoolwriter pages. avoids finalizers.
                foreach (var content in Content.Values)
                    content.Close();
            }

            Content.Clear();
        }