Parent layout wants a RenderModel, but I want to use a custom model

Ok, so I think I finally get how to create custom controllers and use route hijacking enough to tell someone else how to get a basic one going. :wink:

I’ve created a minimal model, controller, and partial view. I have my document type and template, and it all generally seems to work nicely together. My model gets set up in the hijacked Index method in my controller and passed to my view, and I can display the properties I set. I was so excited to finally get that much working.

Where I start to have trouble now is when I use another layout in my template. On our site, we have a “Master” layout, a “Submaster” layout, and then most of the other templates use Submaster.

When my custom model/controller (what is the right terminology? haha) has Layout = null, it’s unstyled, but it shows up on the page.

When I use Submaster as my layout, I get this error:
The model item passed into the dictionary is of type ‘Models.MembersPageModel’, but this dictionary requires a model item of type ‘Umbraco.Web.Models.RenderModel’.

What I think that means is that because SubMaster inherits UmbracoTemplatePage, it’s what wants the RenderModel, even though I’m not referencing any model in SubMaster and my MembersPage template is inheriting Umbraco.Web.Mvc.UmbracoViewPage.

I’ve looked at changing things around so my model inherits from RenderModel, but then I get an error about my model not having a constructor that takes 0 arguments, but then I’m not sure which arguments I’d need to pass in.

So - how do I nest layouts that use two different types? Changing what SubMaster inherits isn’t going to be ideal, because we’re creating several “plugins” like this with different models.

What am I missing?


This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/67536-parent-layout-wants-a-rendermodel-but-i-want-to-use-a-custom-model