How to group partial general views for the specified controllers?

Is it possible to tell ViewEngine to search for partial shared views in additional folders for specified controllers (while NOT for others)?

I am using WebFormViewEngine.

This is what my PartialViewLocations looks like.

public class ViewEngine : WebFormViewEngine { public ViewEngine() { PartialViewLocationFormats = PartialViewLocationFormats .Union(new[] { "~/Views/{1}/Partial/{0}.ascx", "~/Views/Shared/Partial/{0}.ascx" }).ToArray(); } 
+4
source share
1 answer

Sure. Do not modify PartialViewLocationFormats in this case; instead, do:

  public override ViewEngineResult FindPartialView( ControllerContext controllerContext, string partialViewName, bool useCache) { ViewEngineResult result = null; if (controllerContext.Controller.GetType() == typeof(SpecialController)) { result = base.FindPartialView( controllerContext, "Partial/" + partialViewName, useCache); } //Fall back to default search path if no other view has been selected if (result == null || result.View == null) { result = base.FindPartialView( controllerContext, partialViewName, useCache); } return result; } 
+2
source

All Articles