views:

836

answers:

6
The view 'Index' or its master was not found. The following locations were searched:
~/Views/ControllerName/Index.aspx
~/Views/ControllerName/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx

I got this error when using ASP.Net mvc area. The area controller action are invoked, but it seems to look for the view in the 'base' project views instead of in the area views folder.

A: 

You most likely did not create your own view engine.
The default view engine looks for the views in ~/Views/[Controller]/ and ~/Views/Shared/.

You need to create your own view engine to make sure the views are searched in area views folder.

Take a look this post by Phil Haack.

çağdaş
Its wired that the default view engine don't do it, as areas is part of the MVC core now.
Mendy
@Mendy In that case, maybe you did not register your routes with the `MapAreaRoute` extension method in Global.asax?
çağdaş
@çağdaş: MapAreaRoute seems to be removed in MVC2 RC2. and as I said, the routing are good since the controller was invoked correctly.
Mendy
Source: http://www.dcs-media.com/Archive/maparearoute-removed-from-aspnet-mvc-2-rc-OR
Mendy
@Mendy I don't have a chance to test this and I'm taking a wild guess here. But is there any chance you need to provide an `area` keyword when registering your routes? Like this : `routes.MapRoute("Default", "{controller}/{action}", new { area = "SomeArea", controller = "Home", action = "Index" })`
çağdaş
@çağdaş: I don't think it's not a routing problem.
Mendy
+2  A: 

The problem was that I used MvcRoute.MappUrl from MvcContrib to route the context.Routes.

It seems that MvcContrib routing mapper was uncomfortable with area routing.

Mendy
A: 

Did you find a way to get round this or did you just give up on MVCContribs MvcRoute? Having the same problem

Andyroo
I just returned to the 'regular' `routes.MapRoute()` at the time. But **now** you can use the updated MvcContrib that fully support mvc2.
Mendy
Thanks Mendy. I'll give it another go. Could just be me being a noob missing something.
Andyroo
+1  A: 

Check the generated code at *MyArea*AreaRegistration.cs and make sure that the controller parameter is set to your default controller, otherwise the controller will be called bot for some reason ASP.NET MVC won't search for the views at the area folder

public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "SomeArea_default",
            "SomeArea/{controller}/{action}/{id}",
            new { controller = "SomeController", action = "Index", id = UrlParameter.Optional }
        );
    }
Raphael
A: 

It´s still a problem on the Final release.. .when you create the Area from context menu/Add/Area, visual studio dont put the Controller inside de last argument of the MapRoute method. You need to take care of it, and in my case, I have to put it manually every time I create a new Area.

Michael Castro
+1  A: 

What you need to do is set a token to your area name:

for instance:

context.MapRoute(
        "SomeArea_default",
        "SomeArea/{controller}/{action}/{id}",
        new { controller = "SomeController", action = "Index", id = UrlParameter.Optional }
    ).DataTokens.Add("area", "YOURAREANAME");
Shannon Deminick