My need: I need to know know what controller handled the request from within the ViewEngine.
in MVC 5
public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
{
var name = controllerContext.Controller.GetType().Assembly.GetName().Name;
SetLocationFormats(name);
return base.FindView(controllerContext, viewName, masterName, useCache);
}
Notice the ControllerContext.
in MVC 6 a ViewEngine inherits from IViewEngine, which has no concept of the real controller.
public interface IViewEngine
{
ViewEngineResult FindView([NotNull] IDictionary<string, object> context, [NotNull] string viewName);
ViewEngineResult FindPartialView(
[NotNull] IDictionary<string, object> context,
[NotNull] string partialViewName);
}
Questions:
- Why was ControllerContext removed?
- How can I be made whole again as my Views all live in a versioned directories, and I have a mapping that matches a controller's assembly to a versioned directory?
I simply fix up the search paths in my view engine to only look in the proper directories.
\plugins\SomeArea.1.0.0.34\Views\
I would argue that the view engines need as much context information that you can give them.
I traced the problem to the ViewResult class, where;
public override async Task ExecuteResultAsync([NotNull] ActionContext context)
{
}
ActionContext context, would be fantastic to have passed in when you call FindView, instead of cherry picking context.RouteData.Values. Pass the entire context in please.
Thanks