From c4a15f021ffb770a35b78f7d43ba9cbfe704c93a Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Thu, 20 Mar 2014 12:18:02 -0700 Subject: [PATCH] Passing additional data on the ViewContext for resolving views. This will be necessary for partials, and for Components. Basically, the view engine uses a dictionary of data to find the top level view (for an action) - after we do that, we want this context to be sticky, which means we need to pass it around. This ensures that partials and components will be resolved under the same paths as the main view. Currently this 'data' is just the route values - and there is an ongoing discussing about the right design here. The data that's being passed WILL change in the future. --- .../ActionResults/ViewResult.cs | 2 +- src/Microsoft.AspNet.Mvc.Rendering/View/ViewContext.cs | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs b/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs index 729ed5c227..2f14de3cc3 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Mvc context.HttpContext.Response.ContentType = "text/html"; using (var writer = new StreamWriter(context.HttpContext.Response.Body, Encoding.UTF8, 1024, leaveOpen: true)) { - var viewContext = new ViewContext(context.HttpContext, ViewData, _serviceProvider) + var viewContext = new ViewContext(_serviceProvider, context.HttpContext, context.RouteValues, ViewData) { Url = new UrlHelper(context.HttpContext, context.Router, context.RouteValues), }; diff --git a/src/Microsoft.AspNet.Mvc.Rendering/View/ViewContext.cs b/src/Microsoft.AspNet.Mvc.Rendering/View/ViewContext.cs index 8c332513b9..d1d966d63f 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/View/ViewContext.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/View/ViewContext.cs @@ -1,15 +1,17 @@ using System; +using System.Collections.Generic; using Microsoft.AspNet.Abstractions; namespace Microsoft.AspNet.Mvc.Rendering { public class ViewContext { - public ViewContext(HttpContext context, ViewData viewData, IServiceProvider serviceProvider) + public ViewContext(IServiceProvider serviceProvider, HttpContext httpContext, IDictionary viewEngineContext, ViewData viewData) { - HttpContext = context; - ViewData = viewData; ServiceProvider = serviceProvider; + HttpContext = httpContext; + ViewEngineContext = viewEngineContext; + ViewData = viewData; } public HttpContext HttpContext { get; private set; } @@ -19,5 +21,7 @@ namespace Microsoft.AspNet.Mvc.Rendering public IUrlHelper Url { get; set; } public ViewData ViewData { get; private set; } + + public IDictionary ViewEngineContext { get; private set; } } }