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
    Apr 20, 2018 @ 06:07
    Claushingebjerg
    0

    Rendering stack from specific node

    Love the package! I've run into a bump though.

    I use the following to render the stack, easy!

      @foreach(var item in Model.Indhold)
        {
          @Html.Partial(item.DocumentTypeAlias, item)
        }
    

    But im now trying to render a "sidebar" stack defined on the home page by using:

    @foreach(var item in Umbraco.Content(1061).GetPropertyValue("Sidebar"))
        {
           @Html.Partial(item.DocumentTypeAlias, item)
        }
    

    But this throws an error:

    CS1973: 'System.Web.Mvc.HtmlHelper

    Any help appreciated.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Apr 20, 2018 @ 07:28
    Chriztian Steinmeier
    0

    Hi Claus,

    It's most likely because ModelsBuilder converts .Indhold to a collection for you, which using .GetPropertyValue() doesn't.

    First thing I'd try is to use the <T> version (don't ask!) of GetPropertyValue(), e.g.:

    Umbraco.Content(1061).GetPropertyValue<IEnumerable<IPublishedContent>>("Sidebar")

    Hope that helps,

    /Chriztian

  • Claushingebjerg 939 posts 2574 karma points
    Apr 20, 2018 @ 07:34
    Claushingebjerg
    0

    Nope same error. I can see my error message got deleted above, so here is the complete message

    'System.Web.Mvc.HtmlHelper<Umbraco.Web.PublishedContentModels.ImporteretArtikel>' has no applicable method named 'Partial' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
    
  • Claushingebjerg 939 posts 2574 karma points
    Apr 20, 2018 @ 07:42
    Claushingebjerg
    0

    If i do

    @foreach(var item in Umbraco.Content(1061).GetPropertyValue("Sidebar"))
        {
          <p>@item.Name</p>
        }
    

    I get the "Stack" names just fine...

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Apr 20, 2018 @ 08:30
    Chriztian Steinmeier
    0

    Ah - now that makes an entirely different kind of sense :-)

    You probably know I'm not fully qualified to hand out advice about .NET stuff :-) - but the errormessage suggests that it's trying to use dynamics which I've been told we shouldn't... :)

    Anyway - could you try using Umbraco.TypedContent(1061) instead and see where that gets you? (I know it's like walking a tightrope in a dark room!)

    /Chriztian

  • Claushingebjerg 939 posts 2574 karma points
    Apr 20, 2018 @ 09:14
    Claushingebjerg
    0

    Thanks Chriztian.

    Taking one thing that doesn't make sense and combining it with another did the trick :)

    So if you want to render a stack from another node do:

    @foreach(var item in Umbraco.TypedContent(1061).GetPropertyValue<IEnumerable<IPublishedContent>>("Sidebar"))
    
  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Apr 20, 2018 @ 09:16
    Chriztian Steinmeier
    1

    Yeah - that's what I was almost certain of :-)

    So frustrating when solving one thing opens up another can of worms...

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft