Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • higgsy 65 posts 92 karma points
    Apr 11, 2016 @ 14:10
    higgsy
    0

    Umbraco Hybrid Framework and base Views

    Hi all,

    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<StandardContentPage>>
    

    And

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

    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<BaseContentPage>`>
    
    @{
        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?

    I've used some terminology in here that strongly relates to the Hybrid framework, so apologies if I've not made it clear to some...

    Thanks in advance Higgsy

Please Sign in or register to post replies

Write your reply to:

Draft