0

I'm changing the sitecore version from 9.1 to 10.2. I need to pick up Glass Mapper to a higher version (5.8.180). After doing this, new mapper codes are generated. I modify them in the same way as in the previous version:

   public static  class GlassMapperScCustom
    {
        public static IDependencyResolver CreateResolver(){
            var config = new Glass.Mapper.Sc.Config();

            var dependencyResolver = new DependencyResolver(config);
            AddDataMappers(dependencyResolver);
            dependencyResolver.GlassHtmlFactory = new CustomGlassHtmlFactory();

            return dependencyResolver;
        }

        private static void AddDataMappers(DependencyResolver dependencyResolver)
        {
            if (dependencyResolver == null)
            {
                return;
            }

            //replace SitecoreFieldLinkMapper 
            dependencyResolver.DataMapperFactory.Replace<SitecoreFieldLinkMapper, SitecoreFieldCustomLinkMapper>(() => new SitecoreFieldCustomLinkMapper());
            //dependencyResolver.DataMapperFactory.Replace(15, () => new SitecoreFieldCustomLinkMapper());

            //dependencyResolver.DataMapperFactory.Add<SitecoreFieldCustomLinkMapper>(() => new SitecoreFieldCustomLinkMapper());
        }

        public static IConfigurationLoader[] GlassLoaders(){

            /* USE THIS AREA TO ADD FLUENT CONFIGURATION LOADERS
             * 
             * If you are using Attribute Configuration or automapping/on-demand mapping you don't need to do anything!
             * 
             */
            var loader = new AttributeConfigurationLoader("CustomModel");
            return new IConfigurationLoader[]{};
        }
        public static void PostLoad(){
            
        }
        public static void AddMaps(IConfigFactory<IGlassMap> mapsConfigFactory)
        {
            // Add maps here
            // mapsConfigFactory.Add(() => new SeoMap());
        }
    }

I have added built dlls and configuration files to Sitecore. Unfortunately, I get an error when I try to run the page with my layout.

The model item passed into the dictionary is of type 'Sitecore.Mvc.Presentation.RenderingModel', but this dictionary requires a model item of type 'Custom.Models.CommonPage'.

In my layout file I have a model declaration:

@model CustomModel.Models.CommonPage

And code

namespace CustomModel.Models
{
    [SitecoreType(AutoMap = true)]
    public class CommonPage : PageModel
    {

        public virtual string HeaderTitle { get; set; }

        public virtual string HeaderText { get; set; }
        public virtual string HeaderContent { get; set; }
        
        ...

This model has several inheritances, but finally there is an inheritance from:

Sitecore.Mvc.Presentation.RenderingModel

Anyone have any ideas what could be wrong?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.