Copied to clipboard

Flag this post as spam?

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


  • suzyb 474 posts 932 karma points
    Jan 20, 2013 @ 17:11
    suzyb
    0

    Find first node where rich text property not empty

    I want to select the first ancestor of the current node where a property that uses the editor data type is not empty.

    This is the code I have so far

    var node = @Model.AncestorsOrSelf().Where("columnContent != \"\"").First();

    But I get the error "Sequence contains no elements" even though there is a node with the property set.

    I assume this is something to do with the property using the editor data type as the code works if the property uses the simple text data type.

    How can I change my code so it does what I need.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 20, 2013 @ 20:44
    Jan Skovgaard
    0

    Hi Suzyb

    What version of Umbraco are you using? The reason I ask is that with the new MVC support in new Umbraco releases is that there is now 2 ways to do Razor in Umbraco. One way is using macroscript Razor and the other way is to use MVC Razor - And it's 2 different Razor implementations...so :)

    /Jan

  • suzyb 474 posts 932 karma points
    Jan 21, 2013 @ 21:36
    suzyb
    0

    I meant to include umbraco version in my post :/

    Version is v 4.11.3

  • suzyb 474 posts 932 karma points
    Jan 22, 2013 @ 18:02
    suzyb
    0

    With help from a colleague I found out (I think) what the problem has been.  The property is an HTMLstring so obviously can't be checked against a string.

    I've been playing around with it a bit longer and trying a different approach using @Model._columnContent which outputs the value.

    However I have run into another problem.  I only want to output my html if there will be a value going into it so I am trying to use HasValue to check the property.  However as it may be a parent or ancestor that has the value it isn't working.  Does HasValue not have an overload which allows it to check recursivly.  I found this thread which suggests it does however it doesn't seem to be working.

Please Sign in or register to post replies

Write your reply to:

Draft