Copied to clipboard

Flag this post as spam?

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

  • Martin Rud 162 posts 586 karma points c-trib
    May 09, 2021 @ 11:26
    Martin Rud

    How to get the "original" Model when in partial view with it "own" Model?


    I call a view from a template and pass an 'item' obejct to it:

    @Html.Partial("myView"), item)

    It works fine and I can call properties in my 'item' object in the view with


    But how can I get the Model of the page (node) that the view is called from? Model no longer refers to the page that the website visitor is viewing.

  • Marc Goodson 1695 posts 11278 karma points MVP 7x c-trib
    May 09, 2021 @ 11:57
    Marc Goodson

    Hi Martin

    If you make your partial view have an inherits statement at the top eg:

    @inherits UmbracoViewPage<YourCustomModel>

    (instead of any normal MVC @model declaration you might have)

    Then you can access the current page model via:


    eg @Umbraco.AssignedContentItem.Name



  • Martin Rud 162 posts 586 karma points c-trib
    May 09, 2021 @ 12:13
    Martin Rud

    Thanks, Marc! That was just my need! :)


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

    Changed it to:

    @inherits UmbracoViewPage<IPublishedElement>

    And now I can call for instance:

    Umbraco.AssignedContentItem.Children().Where(x => x.IsVisible());
Please Sign in or register to post replies

Write your reply to: