Copied to clipboard

Flag this post as spam?

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


  • Sean Dooley 289 posts 528 karma points
    Sep 15, 2011 @ 14:18
    Sean Dooley
    0

    'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Random'

    Any ideas why the following script is producing the error

    'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Random'

    Source is a contentPicker property, and Limit is a numeric property

    Thanks in advance for any assistance

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
      if (Model.HasProperty("featuredWidgets") && !String.IsNullOrEmpty(Model.FeaturedWidgets.ToString())) {
        foreach (var item in Model.FeaturedWidgets) {
          var node = Model.NodeById(item.InnerText);
          var source = Model.NodeById(node.Source);
          if(source.NodeTypeAlias == "TestimonialArea")
          {
            <div class="widget testimonial">
              <h3>@node.Name</h3>
              @foreach(var testimonial in source.Children.Where("Visible").Random(source.Limit)) {
                @testimonial.BodyText
              }
            </div>
          }
        }
      }
    }
  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Sep 15, 2011 @ 14:28
    Sebastiaan Janssen
    0

    source.Limit is probably interpreted as a string, so you need to cast it to an int first. 

  • Sean Dooley 289 posts 528 karma points
    Sep 15, 2011 @ 14:44
    Sean Dooley
    0

    Thanks Sebastiaan

    If I change source.Limit to an actual number, i.e. 1, so that the script becomes

    @foreach(var testimonial in source.Children.Where("Visible").Random(1)) {
    @testimonial.BodyText
    }

    The same error still occurs. Any ideas?

  • Sean Dooley 289 posts 528 karma points
    Sep 15, 2011 @ 14:47
    Sean Dooley
    0

    If I change Random(1) to Random(), I get the following error

    Cannot implicitly convert type 'umbraco.MacroEngines.DynamicNode' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?)

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Sep 15, 2011 @ 14:47
    Sebastiaan Janssen
    0

    Nope, that works fine for me. I am using a recent nightly of the razor engine though, get umbraco.RazorEngines.dll from a recent nightly and put it in your /bin folder, might help.

  • Sean Dooley 289 posts 528 karma points
    Sep 15, 2011 @ 14:55
    Sean Dooley
    0

    Thanks for your help Sebastiaan. I have grabbed the latest bin and that has solved the problem - brilliant!

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Sep 15, 2011 @ 15:02
    Sebastiaan Janssen
    0

    Beautiful! Would you mind please marking a post as the solution? Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft