Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Can't use PropertyFor rendering tags from commerce content controller

Vote:
 

Basically, whenever I try to run the following code from commerce content page I get the following error: "InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'EPiServer.Core.ContentArea', but this ViewDataDictionary instance requires a model item of type 'OurOrganization.ProductPage.ProductPageViewModel'."

@Html.PropertyFor(x => x.Settings.BlockArea, new { Tag = "wrap" })

The Tag property seems to be treated as a template name, and in the end - in PropertyRenderer.ExistDisplayTemplateWithName - there's a call to ICompositeViewEngine.FindView(...). This seems to return different results even though input is similar.

The way I reproduce the error is by executing the following row from a regular page controller - PageController<T> - and from a commerce controller - ContentController<T>.

var x = _viewEngine.FindView(ControllerContext, "DisplayTemplates/wrap", false);

At least in my case, this results in x.Success being false when called from PageController and x.Success being true when called from ContentController<T>, and the fact that Success is true is what in the end triggers the exception.

Edit: I should also say, my interpretation is that the exception message is misleading.

Edit #2: To make it a little more difficult - also, if there's a outer PropertyFor(...) with a rendering tag, this will be picked up in a inner PropertyFor via DefaultModelTemplateTagResolver, even though the inner PropertyFor didn't specify a rendering tag.

#291699
Edited, Nov 15, 2022 8:49
* 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.