Copied to clipboard

Flag this post as spam?

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

  • Kurisotofa 27 posts 75 karma points
    Aug 17, 2016 @ 22:30

    Unable to render Partial View with a Node/Page parameter

    Sorry guys, I know this will probably be a no-brainer, but I'm unable to solve this myself.

    Imagine that I have an Umbraco page of DocType "parent". Below I have pages of DocType "child".

    I have a template for the "parent" DocType. On the "parent" page, I want to display an info snippet about the first "child".

    Therefore, I have created a simple Partial View in Umbraco :

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    <span>child: @Model.Id</span>

    For the "parent" page, I have a template :

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
        Layout = Nothing;
        var childPage = CurrentPage.Descendants("child").Where("Visible").FirstOrDefault();
    <div>parent: @CurrentPage.Id</div>
    @Html.Partial("child", childPage)

    However, that doesn't seem to work. I'm getting a error message (unfortunately in Dutch, but I'll try to translate) : "CS1973: System.Web.Mvc.HtmlHelper

    I can call the Partial View, with this code :


    But unfortunately (and as was to be expected), the Partial View is executed on the "parent" page, not on the "child" page...

    Any help would be appreciated!

  • Rasmus Eeg 91 posts 457 karma points c-trib
    Aug 18, 2016 @ 05:14
    Rasmus Eeg

    Hi there,

    I belive that if you change from dynamic content to using IPublishedContent it will work. Since UmbracoViewPage expects a IPublishedContent

    Like so:

    @inherits         Umbraco.Web.Mvc.UmbracoTemplatePage
         Layout = Nothing;
         IPublishedContent childPage =    Model.Content.Descendant("child").Where(p=>p.IsVisible())
     <div>parent: @CurrentPage.Id</div>
    @Html.Partial("child", childPage)
Please Sign in or register to post replies

Write your reply to: