Copied to clipboard

Flag this post as spam?

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


  • Kerry Lindsay 5 posts 25 karma points
    Jun 28, 2019 @ 11:01
    Kerry Lindsay
    0

    Strongly Typed Model for Composition and Child Node

    We're creating a baseline site and I'd like to find a way of creating re-usable page elements, e.g. a Call to Action which can be used either as a composition on one type of page where it's static or as a child of another type of page so it can be sorted.

    I'm aware I could use the grid for the sorting, but wondered if there is a way of building the partial view so it can be used for both.

    If I reference the model using View Page @inherits UmbracoViewPage

    If I reference the interface @inherits Umbraco.Web.Mvc.UmbracoViewPage

    Is there a way I can do both?

  • Nik 1144 posts 4732 karma points MVP 2x c-trib
    Jun 28, 2019 @ 14:59
    Nik
    0

    Hey Kerry,

    Your code examples don't appear to have come through properly, but I'm assuming you had something like this:

    @inherits UmbracoViewPage<IMyComposition>
    

    These two variations?

    @inherits UmbracoViewPage<MyComposition>
    

    I think you should be able to use the second version to handle both composition behaviour and full page rendering, although you might need to do a cast in order to get it to work. This is because MyComposition will inherit from IMyComposition which might allow you to pass between the two.

    I've not tested this so it's just a theory.

    Nik

Please Sign in or register to post replies

Write your reply to:

Draft