0

I'm confused, I created an area named 'Admin' and I have these 2 controllers:

/admin/users/...

and

/users/..

Now if I try and link to this url:

/users/list

I get this error:

Multiple types were found that match the controller named 'User'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 

'namespaces' parameter.

I find it confusing why it doesn't work, can't it figure out that this UserController is the one that isn't in the Area?

loyalflow
  • 14,275
  • 27
  • 107
  • 168

2 Answers2

2

When areas are introduced, there is the potential for ambiguity between identically named Controllers ref: http://haacked.com/archive/2010/01/12/ambiguous-controller-names.aspx

Try adding this in your Global.asax

public static void RegisterRoutes(RouteCollection routes)
{
  //all your other routes

  routes.MapRoute(
    "Default",                                              // Route name
    "{controller}/{action}/{id}",                           // URL
    new { controller = "Home", action = "Index", id = "" }, // Defaults
    new[]{"Your.NameSpace"}                       // Namespaces
  );
}
Mister Epic
  • 16,295
  • 13
  • 76
  • 147
0

you can solve this problem by setting the namespace to your routes

like this sample below

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    new[] { "My.Controllers" }
);

context.MapRoute(
    "Admin_default",
    "Admin/{controller}/{action}/{id}",
    new { action = "Index", id = UrlParameter.Optional },
    new[] { "My.Areas.Admin.Controllers" }
);
Milad Hosseinpanahi
  • 1,495
  • 12
  • 20