Decided it. To add the "Shared / Partials" subdirectory that I created to the list of search locations that I searched for when trying to find a partial view in Razor using:
@Html.Partial("{NameOfView}")
First, create a view engine with RazorViewEngine as the base class and add your view positions as follows. Again, I wanted to save all of my partial views in the Partials subdirectory that I created in the default Views / Shared directory created by MVC.
public class RDDBViewEngine : RazorViewEngine { private static readonly string[] NewPartialViewFormats = { "~/Views/{1}/Partials/{0}.cshtml", "~/Views/Shared/Partials/{0}.cshtml" }; public RDDBViewEngine() { base.PartialViewLocationFormats = base.PartialViewLocationFormats.Union(NewPartialViewFormats).ToArray(); } }
Note that {1} in the location format is the name of the controller, and {0} is the name of the view.
Then add this viewer to the MVC ViewEngines.Engines Collection in the Application_Start () method in your global.asax:
ViewEngines.Engines.Add(new RDDBViewEngine());
lamarant Feb 14 '11 at 20:24 2011-02-14 20:24
source share