U4-8431 - Umbraco Hybrid Framework and base Views

Created by Adam 10 May 2016, 14:01:46 Updated by Adam 10 May 2016, 14:02:23

Relates to: U4-8357

I've been using the Umbraco Hybrid Framework for V7 which is working out really well. I'm using the MasterModel/IMasterModel concept which allows me to esentially have pages passed down to my views either as the physical IPublishedContent node, or as a ViewModel essentially - works really well.

One problem im coming up against is the following:

I have a document type setup as follows:

BaseContentPage
    MainBody (Property)
StandardContentPage (inheriting from BaseConentPage)
    CallToActions (Property)
WideContentPage (inheriting from BaseContentPage)

I then have views setup as follows:

@inherits Umbraco.Web.Mvc.UmbracoViewPage<MasterModel>

And

@inherits Umbraco.Web.Mvc.UmbracoViewPage<MasterModel>

They both currently use the _Root layout:

@{ Layout = "~/Views/Layouts/_Root.cshtml"; }

What I'd like to acheive is to have both of these views use a _BaseContentPage.cshtml layout, because both StandardContentPage and WideContentPage share most of the HTML and all of the properties declared in BaseContentPage.

So I went about creating a Layout like so:

@inherits Umbraco.Web.Mvc.UmbracoViewPage<MasterModel`>

@{ Layout = "~/Views/Layouts/_Root.cshtml"; }

@RenderBody()

And updating the views for StandardContentPage.cshtml and WideContentPage.cshtml to use that as their Layout, however then I end up with the error:

Cannot bind source type MyProject.Models.ViewModels.MasterModel1[[MyProject.Models.StandardPage, MyProject.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] to model type MyProject.Models.ViewModels.MasterModel1[[MyProject.Models.BaseContentPage, MyProject.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].

I can understand the error, but at the same time i can't. It's not a logic error because ModelLogic.CreateMasterModel does create the model and populates the properties inherited from BaseContentPage - it's more of a generic MVC problem I believe.

Ultimately my goals with _BaseContentPage.cshtml is to present all of the common properties/content, and then in the StandardContentPage.cshtml/WideContentPage.cshtml views to add all of the properties/content specific to that doc type - but my question is what model/inherits statement should I add to the _BaseContentPage.cshtml view?

Comments

Adam 10 May 2016, 14:02:23

@zpqrtbnk


Priority: Normal

Type: Bug

State: Submitted

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions:

Due in version:

Sprint:

Story Points:

Cycle: