MVC 3 does not look for views under Areas

Viewed 13846

I'm using multiple areas in MVC 3 and I'm having problems with my views not being found. The routing seems to pick up my controllers correctly (all the actions are executing without any problems), but when I return a view MVC simply doesnt find it.

So if I have a simple controller called 'Thing' in an area called 'Some' and I do the following...

public ActionResult Index()
{
    return View("Index");
}

The action is executed correctly, but MVC doesn't find the view and I'll get a message saying something like

The view 'Index' or it's master was not found... And it will show me all the searched locations, which will be

~/Views/Thing/Index.cshtml ~/Views/Shared/Index.cshtml

etc, etc, but it doesn't look in

~/Some/Views/Thing/Index.cshtml

Any ideas on what I am doing wrong?

9 Answers

Just to add another solution here. I was also having this problem but mine was due to having a conflicting "catch all" route in Global.asax.cs

Removing this route fixed the issue.

Try this in RouteConfig.cs.

May be it will be helpful to someone..

      routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new {controller = "Controllername", action = "Actionname", id = UrlParameter.Optional },
            namespaces: new [] { "Projectname.Areas.Areaname.Controllers" }

            ).DataTokens.Add("area", "Areaname");
Related