Copied to clipboard

Flag this post as spam?

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


  • djscorch 67 posts 106 karma points
    Dec 28, 2011 @ 23:19
    djscorch
    0

    Accessing properties when using uQuery.GetNodesByXml

    How do I access properties, I thought i'd just be able to use the . notation as below, but this gives me an error when trying to use previewContent.

    @using uComponents.Core
    @using uComponents.Core.uQueryExtensions

    @{
      string xml = uQuery.GetCurrentNode().GetProperty<string>("articlePreviews");
      var nodes = uQuery.GetNodesByXml(xml);  
        
      <ul>
        @foreach( var node in @nodes )
        {     
         <li>
           <h2>@node.Name</h2>
           <div>@node.previewContent</div>
           <a href="@node.Url">Learn more >></a>
         </li>
        }
      </ul>
      }

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Dec 29, 2011 @ 08:27
    Sebastiaan Janssen
    1

    I believe @node is of type UmbracoNode or something like that, this is not a dynamic node like in the built in Razor engine. So you have to revert back to the "old" way of doing it:

    @node.GetProperty("previewContent").Value

    If you want to use the dynamic "." notation, you could do it just fine without using uQuery, try something like (untested):

    @{  var nodes = Library.ToDynamicXml(Model.GetPropertyValue("articlePreviews")); }
    
    <ul>
    @foreach (var node in nodes) {
      <li>@node.previewContent</li>
    }
    </ul> 
  • 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