Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Rendering NodeContent catalog item gives error. (The model item passed into the dictionary is of type)

Vote:
 

I have CMS + Commerce site. And the CMS part is working fine and i started adding some catalog items and try to render it.  BUt get the error.

Some background

i have a simple catalog item

[CatalogContentType(
        GUID = "ff325833-bf93-449f-bd80-4f138fc92c5d",
        MetaClassName = "Tipping Category",
        DisplayName = "Tipping Category",
        Description = "Display this Tipping category products.")]
    [AvailableContentTypes(Include = new[]
    {        
        typeof(TippingProduct)
    })]
    public class TippingCategory : NodeContent
    {
    }

I have a simple controller to render some content of this NodeContent.

public class TippingCategoryController : ContentController
    {       
        public ActionResult Index(TippingCategory currentContent)
        {          

            return View(currentContent);
        }
    }

And i have a simple view in ~\Views\TippingCategory\index.cshtml

@model TippingCategory

TEST

But when rendering the catalog item (via catalog url) i get the following error:

The model item passed into the dictionary is of type 'Castle.Proxies.TippingCategoryProxy', but this dictionary requires a model item of type 'Hyva.Web.Implementation.ViewModels.IPageViewModel`1[Hyva.Web.Models.Pages.BasePageData]

I think this is because i have my _viewstart.cshtml which has the layout to my _layout.cshtml and that has as a model the IPageViewModel which is my standard for CMS pages.  So now i cannot combine these 2? 

I read this post: https://ejooeun.com/2015/09/25/the-model-item-passed-into-the-dictionary-is-of-type-castle-proxies-myvariationproxy-but-this-dictionary-requires-a-model-item-of-type-episerversite-models-viewmodels-ipageviewmodel1episerver/  but i did it correctly.

What am i missing?

#194986
Edited, Jul 10, 2018 16:26
Vote:
 

Not sure if you had a copy and paste error in your post, but your controller should have been this:

public class TippingCategoryController : ContentController<TippingCategory>



#194993
Edited, Jul 10, 2018 21:40
Vote:
 

Oww.. the editor stripped it out... I changed it in the first post. It was like you said. So thats correct. 

Btw.. i'm on the latest Commerce en CMS packages. 

What else am i missing?

#194999
Jul 11, 2018 7:33
Vote:
 

What is in your view then? 

#195000
Jul 11, 2018 8:08
Vote:
 

My view is like my first post says.. just a simple text (TEST) in a paragraph to see that it works. 

And my correct Model which it uses. 

#195002
Jul 11, 2018 8:19
Vote:
 

Right.

"I think this is because i have my _viewstart.cshtml which has the layout to my _layout.cshtml and that has as a model the IPageViewModel which is my standard for CMS pages.  So now i cannot combine these 2? "

This is true (and I missed it). You can only have one content in a view. One possible solution is to introduce a ViewModel that contains your page data and your catalog content. In your Index action you would create that ViewModel from the currentContent and the page data and return

Both the view will take the ViewModel and then get the page data and catalog content as they need

#195003
Jul 11, 2018 8:35
Vote:
 

I understand but if I check the quicksilver solution I don't see them doing this there. They have their _layout.Cshtml with another model and catalog content view with another model and they just glue together... And I haven't found a post where other have this problem, so I think in my case I'm missing something else .. 

#195009
Jul 11, 2018 9:07
Vote:
 

There is no model in _layout.cshtml in Quicksilver :)

#195010
Jul 11, 2018 9:18
Vote:
 

Oh man ... now this mean i would have to refactor my whole CMS pages and everything to make this work together .... :-(

#195013
Jul 11, 2018 10:07
Vote:
 

you know what is very confusing.. If you follow the concept of setting up your CMS using the Alloy demo(kit) with model in the _layout.cshtml, and now additionally you add the commerce part to it, then you have a problem. That's what i am facing now. 

what would be the best approach to glue those 2 together without refactoring the whole CMS site (multilingual).  

#195018
Jul 11, 2018 11:45
* 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.