2

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?

1 Answer 1

1

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
        };
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

That's not my problem... The controller (or ViewEngine...) can find my views, unless they are in an area. Your suggested solution won't help in my case, but thx anyway :)
Why not, have you looked at the first article? Areas is just another folders above views, you can solve this problem going the same way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.