MVC 3 does not look for views under Areas

If your controller has the same name as the area, your controller will be picked up by the default base route {controller}/{action} BEFORE it checks the area route and therefore will look for the view in the root /views instead of in the area /views. Renaming either the area or the controller will resolve this.


Ok, sorry to have to answer my own question but nobody really gave me the answer I was looking for. It seems my problem was with custom routing.

To recreate the problem, I created a blank MVC 3 project and added an Area called 'Some' and a controller in that area called 'Thing'. On thing I created an Index action which simply returned a view. I then added the Index view to ~/Areas/Some/Views/Thing/Index.cshtml

Great. So when I hit /Some/Thing/Index it returns the view correctly.

Now go and add a route to Global.asax that looks like this:

routes.MapRoute(
                "Custom", // Route name
                "Bob", // URL with parameters
                new { area = "Some", controller = "Thing", action = "Index" }
                );

Now when I navigate to /Bob I get the error I mentioned - MVC doesn't find the view. To fix this problem I had to register this route in the SomeAreaRegistration class instead of Global.asax. I also didn't need the 'area' property, so it looks like this.

    context.MapRoute(
        "Custom", // Route name
        "Bob", // URL with parameters
        new { controller = "Thing", action = "Index" }
        );

Make sure that you have a file called SomeAreaRegistration.cs on your "Some" area. this file should contain something like the following:

public class SomeAreaRegistration : AreaRegistration
{
    public override string AreaName
    {
        get
        {
            return "Some";
        }
    }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Some_default",
            "Some/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional }
        );
    }
}

Try add following route in global.asax:

 context.MapRoute(
                "default",
                "Some/{controller}/{action}/",
                new { controller = "Thing", action = "Index"}
            );