asp.net mvc - Having issue with multiple controllers of the same name in my project -
i running following error asp.net mvc 3 project:
multiple types found match controller named 'home'. can happen if route services request ('home/{action}/{id}') not specify namespaces search controller matches request. if case, register route calling overload of 'maproute' method takes 'namespaces' parameter.
the request 'home' has found following matching controllers: mycompany.myproject.webmvc.controllers.homecontroller mycompany.myproject.webmvc.areas.company.controllers.homecontroller
i have homecontroller in default controller folder, class name of mycompany.myproject.webmvc.controllers.homecontroller.
my registerroutes method, in global.asax, looks like:
public static void registerroutes(routecollection routes) { routes.ignoreroute("{resource}.axd/{*pathinfo}"); routes.maproute( "default", // route name "{controller}/{action}/{id}", // url parameters new { controller = "home", action = "index", id = urlparameter.optional } // parameter defaults ); }
i have area called company, homecontroller in default controller folder area, class name of mycompany.myproject.webmvc.areas.company.controllers.homecontroller.
the registerarea method in companyarearegistration file looks like:
public override void registerarea(arearegistrationcontext context) { context.maproute( "company_default", "company/{controller}/{action}/{id}", new { area = "company", action = "index", id = urlparameter.optional } ); }
this leading error highlighted @ beginning of post. struggling trying piece solution various other posts, no luck.
is possible have homecontroller in default controllers folder , 1 in each area? if so, need make (assuming do) changes configuration file make work?
any appreciated!
the error message contains recommended solution: "if case, register route calling overload of 'maproute' method takes 'namespaces' parameter."
routes.maproute( "default", // route name "{controller}/{action}/{id}", // url parameters new { controller = "home", action = "index", id = urlparameter.optional }, // parameter defaults new string[] { "mycompany.myproject.webmvc.controllers"} );
this make http://server/ go homecontroller's index action is, think, want. http://server/company/home go company area's homecontroller's index action, defined in area registration.
Comments
Post a Comment