Copied to clipboard

Flag this post as spam?

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


  • Frans van Ek 11 posts 42 karma points
    Jul 28, 2015 @ 12:42
    Frans van Ek
    0

    DynamicPublishedContentList does not contain a definition for 'Any'

    Why is this error.

    Clean install; mvc4 startup project in VS 2013.

    install umbraco (nuget)

    install MVC 5 (nuget)

    fails on:

    home.Children.Any() in a razor.

    managed to get it working with...

    var helper = home.Children as DynamicPublishedContentList; } @if (helper.Any())

    why is this and how can it be solved?

    kind regards,

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Jul 29, 2015 @ 10:43
    Alex Skrypnyk
    0

    Hi Frans,

    Try to use strongly typed objects, DynamicPublishedContentList is dangerous and unpredictable.

    Thanks

  • John Churchley 272 posts 1258 karma points c-trib
    Jul 29, 2015 @ 11:13
    John Churchley
    0

    Have you tried? .Children.Count() > 0?

  • Frans van Ek 11 posts 42 karma points
    Jul 29, 2015 @ 11:59
    Frans van Ek
    0

    Hi thanks for the reply.

    @alex since i don't know the type of the children. i need to have some thing generic. This is what the dynamic contains at the moment. Can you elaborate why is it unpredictable and/or dangerous.

    @John. Count() doesn't work either.... Since it's a dynamic... :-(

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Jul 29, 2015 @ 12:00
    Alex Skrypnyk
    0

    All nodes are the same type, why you don't know what type ?

    DocType is different.

  • Frans van Ek 11 posts 42 karma points
    Jul 29, 2015 @ 12:12
    Frans van Ek
    1

    So what kind of typed objects should i use.

    Is there a reason why the items are dynamic instead of a strongly typed list?

  • jivan thapa 194 posts 681 karma points
    Jul 29, 2015 @ 13:58
    jivan thapa
    100

    Have you try like this one?

    var typedHome = (IPublishedContent) home;
        if (typedHome.Children.Any())
        {
            // do something
        }
    
  • Frans van Ek 11 posts 42 karma points
    Jul 30, 2015 @ 07:47
    Frans van Ek
    0

    Thanks Jivan..

    Only problem is that intellisense still doesn't show the any extention. Do i need to add a using in order to get this working?

    kind regards,

  • jivan thapa 194 posts 681 karma points
    Jul 30, 2015 @ 08:06
    jivan thapa
    0

    Could you try this one? @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

  • Frans van Ek 11 posts 42 karma points
    Jul 30, 2015 @ 08:55
    Frans van Ek
    0

    I had this already... but that doesn't work.

    {

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @using Umbraco.Core.Models @using Umbraco.Web.Models

    @{ IPublishedContent home = CurrentPage.Site();

    if (home.Children.Any())
    {
        <h1>working</h1>
    }
    

    }

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies