I'm starting a new ASP.NET MVC project, and I decided to put my controllers in a different assembly. Evertyhing works fine, but I have hit a problem: I created a new area in my MVC Project, called Administration. I have an AdminController Class in my seperate assembly which is supposed to return views from my Admin area, but everytime it tries to return a view, it looks for it in the wrong place (~/Admin/SomeView.cshtml Instead of ~/Administration/Admin/SomeView.cshtml) How can I tell the controller to look for views in the wanted area?

有帮助吗?

解决方案

Please take a look into this article. And also you problem was answered here.

Basically you will need to extend MvcViewEngine, to tell MVC to look for your Views in the different from standatd pathes:

public class YourMegaViewEngine : WebFormViewEngine
{
    public YourMegaViewEngine ()
    {
        ViewLocationFormats = new string[]
        {
            "~/Views/Administration/{1}/{0}.cshtml" //I may be wrong for you case, but this is the place to puth you path
        };
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top