0

I need do put a new home in new area but im have a error: Multiple types were found that match the controller named 'Home'. 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. my new area

Areas/Administrativo/Controllers/HomeController

Areas/Administrativo/Views/Home

my AdministrativoAreaRegistration

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

    }

in Global i have

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new[] { "Preparacao.Gerenciar.Web.Controllers" } // Parameter defaults
        );
    }
Kapil Khandelwal
  • 15,958
  • 2
  • 45
  • 52
thefirexa
  • 3
  • 3

1 Answers1

2

You should specify the namespace constraint in your area route registration (check if the namespace is correct):

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "Administrativo_default",
        "Administrativo/{controller}/{action}/{id}",
        new { controller = "Home", action = "Index", id = UrlParameter.Optional },
        new[] { "Preparacao.Gerenciar.Web.Areas.Administrativo.Controllers" }
    );
}

the same way you did with your main route registrations:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional },  // Parameter defaults
        new[] { "Preparacao.Gerenciar.Web.Controllers" }
    );
}
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • thanks man I was putting new[] {"Preparacao.Gerenciar.Web.Controllers"} instead of new[] { "Preparacao.Gerenciar.Web.Areas.Administrativo.Controllers" } – thefirexa Feb 27 '13 at 13:59
  • i put this but i get the this error don't work for me, do you have more idea? – thefirexa Feb 27 '13 at 14:26
  • if i put http://localhost/HelpProvasGerenciar/Administrativo/ i get 404 and if http://localhost/HelpProvasGerenciar/ i get multiples types .... – thefirexa Feb 27 '13 at 14:28
  • this works fine just Administrativo but in default localhost/HelpProvas don't work i get error multiples types – thefirexa Feb 27 '13 at 14:38
  • public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new []{ "Preparacao.Gerenciar.Web.Controllers" } ); } my project name is Preparacao.Gerenciar.Web.Controllers – thefirexa Feb 27 '13 at 14:42
  • Did you verify whether the namespace for your HelpProvasController` class is `Preparacao.Gerenciar.Web.Controllers`? – Darin Dimitrov Feb 27 '13 at 14:43
  • i don't have HelpProvasController... helpprovas is my virtual directory – thefirexa Feb 27 '13 at 14:45
  • namespace Prepracao.Gerenciar.Web.Controllers from default and namespace Preparacao.Gerenciar.Web.Areas.Administrativo.Controllers – thefirexa Feb 27 '13 at 16:05
  • problems fixed in my home default namespace Prepracao.Gerenciar.Web.Controllers from default and namespace "Prepracao" i put "Preparacao" and it's work fine thanks – thefirexa Feb 27 '13 at 17:50