Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 karma points
    Mar 14, 2019 @ 13:30
    Claushingebjerg
    0

    Nested content - multiple doctypes - render in partials

    im trying to render a nested content in x number of partials based on the different doc types used.

    i have the main partial set up like this:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
        var items = Model.Value<IEnumerable<IPublishedElement>>("content");
        foreach (var item in items)
            {
                @Html.Partial("~/views/partials/" + item.ContentType.Alias + ".cshtml", item)
            }
    }
    

    then i have setup the needed "subpartials" and they load fine. My problem arises when trying to get actual data from the nested content in the sub partial. Just doing:

    @Model.GetProperty("spalte1").Value()
    

    returns: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'object' does not contain a definition for 'Value'

    Any pointers?

  • Nigel Wilson 945 posts 2077 karma points
    Mar 14, 2019 @ 18:19
    Nigel Wilson
    0

    Hi Claushingebjerg

    As a test within your loop in the main partial, how about putting an if statement to target one of your nested content types and trying to ouptut a value - this will help identify where the issue lies, e.g.

    foreach (var item in items)
    {
         if (item.ContentType.Alias == "one nested content type" {
              @item.GetProperty("spalte1").Value()
         } else {
              @Html.Partial("~/views/partials/" + item.ContentType.Alias + ".cshtml", item)
         }
    }
    

    The other consideration is what your sub partials are setup like - maybe post one example here ?

    Hope this helps

    Nigel

  • Claushingebjerg 939 posts 2574 karma points
    Mar 15, 2019 @ 07:36
    Claushingebjerg
    0

    Hi Nigel

    The example is in my first post. First code block is the main partial. Second block is the sub partial

  • Claushingebjerg 939 posts 2574 karma points
    Mar 15, 2019 @ 07:51
    Claushingebjerg
    0

    BTW if i do

     @Model.GetProperty("spalte1")
    

    in the subpartial it returns

    Umbraco.Web.PublishedCache.PublishedElementPropertyBase

  • Nigel Wilson 945 posts 2077 karma points
    Mar 15, 2019 @ 17:58
    Nigel Wilson
    0

    How about @Model.GetProperty("spalte1").Value.ToString() ?

  • Claushingebjerg 939 posts 2574 karma points
    Mar 18, 2019 @ 08:08
    Claushingebjerg
    0

    Well... As Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'object' does not contain a definition for 'Value' i cant convert it to a string ;)

Please Sign in or register to post replies

Write your reply to:

Draft