After using Razor generator, MVC cannot find views in customized location if they are from a library.
For example:
public ActionResult Index()
{
// this works perfect
// return View("~/Views/CustomizedLocation/foo/baz.cshtml");
// this does not work
return View("~/Views/CustomizedLocation/foo/bar.cshtml");
}
See sample project:
- "bar.cshtml" is from a lib, whereas "baz.cshtml" is in the web app itself.
- I do NOT want to register "CustomizedLocation" in the view finder for many reasons. I only want to pick it up when needed.
Should be a simple problem but I could not find any existing discussions. Sorry if dup.
Comments: Thanks David that is the key --- "register the Library as a view engine". Turned out that every single DLL that has view in it should be registered such as: public static void AddViewEngineForAssembly(Assembly dll) { var engine = new PrecompiledMvcEngine(dll); ViewEngines.Engines.Add(engine); // StartPage lookups are done by WebPages. VirtualPathFactoryManager.RegisterVirtualPathFactory(engine); } if you have N such libraries, you will need N PrecompiledMvcEngine(s).
For example:
public ActionResult Index()
{
// this works perfect
// return View("~/Views/CustomizedLocation/foo/baz.cshtml");
// this does not work
return View("~/Views/CustomizedLocation/foo/bar.cshtml");
}
See sample project:
- "bar.cshtml" is from a lib, whereas "baz.cshtml" is in the web app itself.
- I do NOT want to register "CustomizedLocation" in the view finder for many reasons. I only want to pick it up when needed.
Should be a simple problem but I could not find any existing discussions. Sorry if dup.
Comments: Thanks David that is the key --- "register the Library as a view engine". Turned out that every single DLL that has view in it should be registered such as: public static void AddViewEngineForAssembly(Assembly dll) { var engine = new PrecompiledMvcEngine(dll); ViewEngines.Engines.Add(engine); // StartPage lookups are done by WebPages. VirtualPathFactoryManager.RegisterVirtualPathFactory(engine); } if you have N such libraries, you will need N PrecompiledMvcEngine(s).