Copied to clipboard

Flag this post as spam?

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


  • Dinovo 7 posts 87 karma points
    Jun 21, 2018 @ 06:13
    Dinovo
    0

    Share partial views across layouts?

    What is the best approach to sharing a partial view, across different view files?

    For instance, i have a section on all pages, that are the same; a small section with related links, that simply checks if "Model.RelatedLinks" is populated, and if it is, displays them.

    My Doc Types are built with compositions, so the related links section, is shared across many doc types.

    But, when i try to use it, i get an error like; Cannot bind source content type Umbraco.Web.PublishedContentModels.DocType1 to model type Umbraco.Web.PublishedContentModels.DocType2.

    I the partial view for my related links, i have: @inherits UmbracoViewPage<DocType1>. So this partial view, only works, when i use it, on a view of the type @inherits UmbracoViewPage<DocType1>

    What is the best approach forward, so i do not have to have the same snippet of code on each view, but can gather it into views?

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Jun 21, 2018 @ 07:59
    David Brendel
    101

    Hi Dinovo,

    when you use compositions, the doctypes are used as actual interfaces to your doc types. So I would suggest that you use that "composition interface" in your partial view. Then you can use every doc type that uses the composition.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jun 21, 2018 @ 08:12
    Dave Woestenborghs
    2

    Hi Dinovo,

    Like David all ready mentioned you should use the composition interface or doctype on your partial view then.

    Some thing like this

    @inherits UmbracoViewPage<IComposotionInterface>
    

    or

    @inherits UmbracoViewPage<ComposotionDocType>
    

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft