Copied to clipboard

Flag this post as spam?

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


  • Peter S 169 posts 587 karma points
    Jun 10, 2014 @ 15:55
    Peter S
    0

    Can't get to property in Razor markup

    I can't get to one of my properties in the Razor markup. I've added the this piece of code in code behind:

    var childPages = CurrentPage.Children.OrderByDescending(x => x.CreateDate);            
    ViewBag.Threads = childPages;

    I can do a foreach on these in markup and get to all the common properties like Name, Id, CreateDate, etc. but when I try to get one of my custom properties the closest I get is @thread.GetProperty("owner").ToString() wich gives me Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty but I can't get the value. How do I do this?

     

  • Peter S 169 posts 587 karma points
    Jun 10, 2014 @ 15:57
    Peter S
    0

    It code behind the code below works great but in Razor it crashes and says that there's no definition for Value.

    item.GetProperty("owner").Value.ToString();

  • Bert 128 posts 251 karma points
    Jun 10, 2014 @ 16:04
    Bert
    0

    The value might not be set. You can check it with:

    .HasProperty(string propertyAlias) - Returns a boolean value representing if the DynamicNode has a property with the specified alias.

    .HasValue(string propertyAlias) - Retruns a boolean value representing if the DynamicNode property has had a value set.

     

  • Peter S 169 posts 587 karma points
    Jun 10, 2014 @ 16:09
    Peter S
    0

    It's set. I know so.

  • Peter S 169 posts 587 karma points
    Jun 10, 2014 @ 16:10
    Peter S
    0

    If I do this I get it:

    @{
            umbraco.NodeFactory.Node node = new umbraco.NodeFactory.Node(thread.Id);
    }

    @node.GetProperty("owner").ToString();

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 12, 2014 @ 01:36
    Jeavon Leopold
    0

    Isn't it just @thread.Owner ?

  • 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