Try our conversational search powered by Generative AI!

The routed data is of type..and the binding context data ... is of type ..., neither of which matches the requested type...

Vote:
 

Hi Folks,

getting an error with an ecommerce project. Anytime I try to navigate to a catalog item I get this error.  The 'requested type' is always AccessoryProduct in spite of whatever class of item I am actually trying to access. 

Strangely enough this seems to coincide with the alphabetical listing of the catalog classes.  The erroneous requested type was always 'FashionNode', then I noticed it changed to BlouseProduct when that was added.  I added a WatchProduct and AccessoryProduct as a test and noticed it had changed to always requesting an AccessoryProduct.

I've looked around for a solution and the problem has usually seemed to be the classes loaded into the controller, but they all seem to be correct and matching with the right views.

Has anyone one come across this one before?

Many thanks,

Dave

#249764
Mar 09, 2021 9:54
Vote:
 

CatalogueControllerBase is Custom Controller base? Is it inherited from CatalogContentBase?

Did you implement custom routing for the catalogue in Commerce Initialization?

#249781
Mar 09, 2021 20:07
Vote:
 

CatalogControllerBase is a custom controller yeah, inheriting from ContentController. 

That's all my routing code here, I think it's fairly standard unless I've missed something.

using System.Web.Mvc;
using System.Web.Routing;
using EPiServer.Commerce.Routing;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.ServiceLocation;

namespace CommerceTraining.Infrastructure
{
    [InitializableModule]
    [ModuleDependency(typeof(EPiServer.Commerce.Initialization.InitializationModule))]
    public class EPiServerCommerceInitializationModule : IConfigurableModule
    {
        public void Initialize(InitializationEngine context)
        {
            CatalogRouteHelper.MapDefaultHierarchialRouter(RouteTable.Routes, false);
        }

        public void Preload(string[] parameters) { }

        public void Uninitialize(InitializationEngine context)
        {
        }

        public void ConfigureContainer(ServiceConfigurationContext context)
        {
            DependencyResolver.SetResolver(new StructureMapDependencyResolver(context.StructureMap()));
        }
    }
}
#249815
Mar 10, 2021 9:35
Vote:
 

Hi,

As a thought, shouldn't your CatalogControllerBase inherit ContentController<T> rather than ContentController<CatalogContentBase>? Like this:

public class CatalogControllerBase<T> : ContentController<T> where T : CatalogContentBase
{
    //Controller code goes here...
}

By having all of your controllers ultimately inheriting ContentController<CatalogContentBase>, I'd imagine Episerver will see that as a bunch of controllers which handle CatalogContentBase rather than your specific catalog content types.

#249834
Mar 10, 2021 14:29
Quan Mai - Mar 11, 2021 10:51
Good call Paul :)
Vote:
 

Do you have any custom router? 

#249841
Mar 10, 2021 16:24
Vote:
 

It seems like the problem is with the base controller. I tried your controller and I got the same error. 

Example If you want to create One base controller for all catalogue pages 

https://github.com/episerver/Foundation/blob/develop/src/Foundation/Features/CatalogContent/CatalogContentControllerBase.cs 

If you want a Base controller for categories only (Nodes)

public class NodeControllerBase<T> : ContentController<T> where T : NodeContentBase
{
//....
}
#249871
Mar 11, 2021 0:16
Vote:
 

Thanks guys, yep the problem was in the CatalogControllerBase. Switched it out to;

public class CatalogControllerBase<T> : ContentController<T> where T : CatalogContentBase

and it works perfectly now.

#249888
Mar 11, 2021 9:30
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.