I am pretty inexperienced with .net and just started learning MVC. I ran into a problem with detecting multiple controllers:
“Several types were found that match the controller named“ reviews. ”This can happen if the route serving this request ('{controller} / {action} / {id}') does not define a namespace for the search that matches the request If so, register this route by overloading the MapRoute method, which accepts the namespaces parameter.
I recently added a new “admin” area to my application, and inside that I have a “ReviewController”. There is also a “ReviewController” in the main application folder:
ah - as a new user, I can’t post the image, but basically I have a “ReviewController” in the “Controllers” and in the “Scopes / Admin / Controllers”.
I have 2 routes configured so far:
Default route in Global.asax.vb
Shared Sub RegisterRoutes(ByVal routes As RouteCollection) routes.IgnoreRoute("{resource}.axd/{*pathInfo}") ' MapRoute takes the following parameters, in order: ' (1) Route name ' (2) URL with parameters ' (3) Parameter defaults routes.MapRoute( _ "Default", _ "{controller}/{action}/{id}", _ New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional}, _ {"PowellCasting/Controllers"} ) End Sub Sub Application_Start() AreaRegistration.RegisterAllAreas() System.Data.Entity.Database.SetInitializer(New System.Data.Entity.DropCreateDatabaseIfModelChanges(Of Models.PowellCastingEntites)) Database.SetInitializer(Of PowellCastingEntites)(New PowellCastingInitializer()) RegisterGlobalFilters(GlobalFilters.Filters) RegisterRoutes(RouteTable.Routes) ControllerBuilder.Current.DefaultNamespaces.Add("PowellCasting/Controllers") End Sub
Area Route in AdminAreaRegistration
Namespace PowellCasting.Areas.Admin Public Class AdminAreaRegistration Inherits AreaRegistration Public Overrides ReadOnly Property AreaName() As String Get Return "Admin" End Get End Property Public Overrides Sub RegisterArea(ByVal context As System.Web.Mvc.AreaRegistrationContext) context.MapRoute( _ "Admin_default", _ "Admin/{controller}/{action}/{id}", _ New With {.Controller = "Dashboard", .action = "Index", .id = UrlParameter.Optional} ) End Sub End Class End Namespace
After reading the problems that I had, I added a few bits of code:
My Admin controllers have the correct namespace
- The PowellCasting.Areas.Admin namespace, not just PowellCasting.
- I have RegisterAllAreas installed in the global
- ControllerBuilder.Current.DefaultNamespaces.Add ("PowellCasting / Controllers") is used to indicate the default route.
The specific problem that I am facing right now is that when I go to "/ Reviews", I get the above error from several controllers, in particular:
* The following matching controllers were found in the "reviews" request: PowellCasting.PowellCasting.Areas.Admin.ReviewsController
PowellCasting.PowellCasting.ReviewsController *
I turned on the route debugger and only shows one match:
ah - as a new user, I can not send the image, but it shows:
Admin / {controller} / {action} / {id} as FALSE
and
{controller} / {action} / {id} as TRUE
This is as expected, so I don’t know why I am getting this problem.
I read about overloading the maproute method with namespace, but couldn't find an example in VB (loads in C #). But I tried this:
Public Overrides Sub RegisterArea(ByVal context As System.Web.Mvc.AreaRegistrationContext) context.MapRoute( _ "Admin_default", _ "Admin/{controller}/{action}/{id}", _ New With {.Controller = "Dashboard", .action = "Index", .id = UrlParameter.Optional}, _ vbNull, {"PowellCasting/Areas/Admin/Controllers"} ) End Sub
and
Shared Sub RegisterRoutes(ByVal routes As RouteCollection) routes.IgnoreRoute("{resource}.axd/{*pathInfo}") ' MapRoute takes the following parameters, in order: ' (1) Route name ' (2) URL with parameters ' (3) Parameter defaults routes.MapRoute( _ "Default", _ "{controller}/{action}/{id}", _ New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional}, _ vbNull, {"PowellCasting/Controllers"} ) End Sub
but without success.
I am sure it should be simple, and I have tried several things - it is very frustrating. Any help would be really appreciated.
My first post here is Hello! :)