Can I specify a custom location to “search for views” in ASP.NET MVC?

后端 未结 10 2324
故里飘歌
故里飘歌 2020-11-22 06:08

I have the following layout for my mvc project:

  • /Controllers
    • /Demo
    • /Demo/DemoArea1Controller
    • /Demo/DemoArea2Controller
    • etc
10条回答
  •  日久生厌
    2020-11-22 06:36

    Try something like this:

    private static void RegisterViewEngines(ICollection engines)
    {
        engines.Add(new WebFormViewEngine
        {
            MasterLocationFormats = new[] {"~/App/Views/Admin/{0}.master"},
            PartialViewLocationFormats = new[] {"~/App/Views/Admin//{1}/{0}.ascx"},
            ViewLocationFormats = new[] {"~/App/Views/Admin//{1}/{0}.aspx"}
        });
    }
    
    protected void Application_Start()
    {
        RegisterViewEngines(ViewEngines.Engines);
    }
    

提交回复
热议问题