Problems with controller routing

Hi, my code has an override Index controller to make a regional property listing page display when using the search form if a region is picked.

This works consistently, but I’ve noticed these errors appearing:

Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints. Matches: 
Galbraith.Controllers.RegionalListingPageController.Index (Galbraith)
Galbraith.Controllers.RegionalListingPageController.Index (Galbraith)

I’m a bit perplexed at how to approach this problem, as I suspect it could be a holdover from my pretty ropey conversion from v8 to v13 as I am not experienced in converting .NET to .NETCore

 public class RegionalListingPageController(ILogger<PropertyListingController> logger, ICompositeViewEngine compositeViewEngine, IUmbracoContextAccessor umbracoContextAccessor, IPropertySearchService searchService, UmbracoHelper Umbraco, IConfiguration configuration) : PropertyListingController(logger, compositeViewEngine, umbracoContextAccessor, searchService, Umbraco, configuration)
 {
     public override ActionResult Index(ContentModel model, [FromQuery] PropertySearchQuery sq)
     {
         var listingPage = model.Content as RegionalListingPage;
         sq.RegionId = listingPage.Region?.Cast<Region>().ReapitId;
         return (ActionResult)base.Index(model, sq);
     }
 }

This is all the code in that controller, inline with what the older developer created

If you’ve upgraded it form v8 to v13, could it have 2 dlls for the Website still in the bin folder? Since the v8 → v9 requires you to have a new project and then update the database, the dll files might have been copied over and the application reads both and see your duplicate. Are you seeing 2 versions of the Web project/project containing the controller?

If you completely clean the bin folder out and build again, are you still getting the same issue?

1 Like

I’ll take a look this morning, would be interesting as a solution but I think it’s a fairly clean project

Just a single dll as far as I can see. I wonder if I need to change the old method, maybe it needs to be part of the main property listing page controller rather than using its own?

short answer: I think you need to rename your action from Index to something else.

Long answer:
From the code in your example, I see that you have a method Index that accepts ContentModel and PropertySearchQuery.

Does your base class PropertyListingController inherit from RenderController?

The RenderController comes with a method called Index. The application does not know if it should choose the one from RenderController or your custom one. Note that query parameters are not used to determine which controller action to invoke. You need to change the name of your action from Index to something else.

So what should this ‘something else’ be?
You likely have a template for the content that you render. The name of the action can be the alias of the template that you assigned to the content.

1 Like