Small EPiServer Commerce Gotcha

Here is a quick “gotcha” that you might run into if you are adding EPiServer.Commerce to your CMS site:

Server Error in ‘/’ Application.


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.IPageViewModel`1[EPiServerSite.Models.Pages.SitePageData]’.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: 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.IPageViewModel`1[EPiServerSite.Models.Pages.SitePageData]’.

Source Error:

 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

 

[InvalidOperationException: The model item passed into the dictionary is of type 'Castle.Proxies.MyVariationProxy', but this dictionary requires a model item of type 'CmsChallenge.Models.ViewModels.IPageViewModel`1[CmsChallenge.Models.Pages.SitePageData]'.]

 

Most likely, your controller for MyVariation (which inherits from EPiServer.Commerce.Catalog.ContentTypes.VariationContent) looks something like this:

    public class MyVariationController : ContentController<MyVariation>
    {
        public ActionResult Index(MyVariation currentPage)
        {
            // ...
            return View(currentPage);
        }
    }

The answer to this problem can be found in the section titled “Defining rendering templates”: http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Commerce/8/Content/commerce-rendering-templates/

Make sure you are passing “currentContent” instead of “currentPage” to your Index action, and you’ll be good to go.

 

Leave a Comment

Your email address will not be published. Required fields are marked *