Copied to clipboard

Flag this post as spam?

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


  • Michael Friedrich 20 posts 97 karma points
    Dec 08, 2011 @ 09:49
    Michael Friedrich
    0

    How to loop through PropertyResult?

    I have several related Link with media property in my Document.

    If I use the code:

    @foreach (var link in @fund.FundProductInfoEN) {

    everything works like expected. But I have an 1:1 Multilanguage website and the language code is stored in the session. If I change the code to get the language code from the session I have to use the .GetProperty or .GetPropertyValue method. But if I change the code to:

    @foreach (var link in @fund.GetProperty("fundProductInfo" + Session["Lang"])) {

    the following error occurs:

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

    I use Version 4.7.1. Thanks for any hint.


  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 08, 2011 @ 10:15
    Dave Woestenborghs
    0

    Does this datatype return xml ? Then you should cast your property value to DynamicXml

  • Michael Friedrich 20 posts 97 karma points
    Dec 08, 2011 @ 10:39
    Michael Friedrich
    0

    The datatype is an ucomponent related links with media and stores these xml:

              <fundProductInfoEN>
                <links>
                  <link title="Factsheet" link="1190" type="media" newwindow="1" />
                  <link title="Factsheet institutional" link="1191" type="media" newwindow="1" />
                </links>
              </fundProductInfoEN>

    But how do I cast it to DynamicXml? do I need a using for this? If i try

    @foreach (var link in @fund.GetProperty("fundProductInfo" + Session["Lang"]) as DynamicXml) {

    I get the error that no Namespace or Type exists.

     

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 08, 2011 @ 11:17
    Dave Woestenborghs
    0

    I think you need this

    DynamicXml xml = Library.ToDynamicXml(fund.GetPropertyValue("fundProductInfo" + Session["Lang"]));

     

    foreach(var link in xml.links) {

     

    }

  • Michael Friedrich 20 posts 97 karma points
    Dec 08, 2011 @ 11:27
    Michael Friedrich
    0

    Same error: Type or Namespace 'DynamicXml' could not be found (using directive or assembly reference missing?)

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 08, 2011 @ 11:41
    Dave Woestenborghs
    0

    you should have this directive in your macro 

    @using umbraco.MacroEngines;

  • Michael Friedrich 20 posts 97 karma points
    Dec 08, 2011 @ 17:25
    Michael Friedrich
    0

    I had to cast the loop item to dynamic to be able to access the attributs of the items.

    This is my code now:

    @using umbraco.MacroEngines
    .
    .
    .
                       @{DynamicXml xml = Library.ToDynamicXml(fund.GetPropertyValue("fundProductInfo" + Session["Lang"]));}
                       @foreach (dynamic lnk in xml) {
                         <a href="@lnk.link">@lnk.title</a><br />                    }

     

Please Sign in or register to post replies

Write your reply to:

Draft