Copied to clipboard

Flag this post as spam?

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


  • Danny Winbourne 33 posts 54 karma points
    Jan 31, 2012 @ 12:04
    Danny Winbourne
    0

    Dynamic XML issue

     

    This one is driving me mad, so I am hoping someone can help!!

    I have a "Related Links" property on my page, which links to several other pages in the site.

    I loop though each one with

     

    @foreach (var item in pageModel.carouselItems.BaseElement.Elements("link"))
    { dynamic carouselItem = new DynamicNode(@item.Attribute("link").Value); }

    Each, "carouselItem" has got various properties, but the one I am having issues with is a "URL Picker", property name "captionUrl" (from Ucomponents).

    If I output "carouselItem.captionUrl", I get "umbraco.MacroEngines.DynamicXml"

    But, if I try "carouselItem.captionUrl.url", I get an error "'string' does not contain a definition for 'url'"

     

    @item.Attribute("link").Value is pushing out ints, one of which is "1072", so I tried the following code:

     


            int number = 1072;
            dynamic testNode = new DynamicNode(number);
            <div> @testNode.captionUrl.url</div>

    The above works fine, and outputs the URL as expected.

    So, I tried setting an int value to @item.Attribute("link").Value. The following code shows that it is being set correctly as an int:

     

            int number2 = int.Parse(@item.Attribute("link").Value.ToString());
            <div>Number: @number2 Type: @number2.GetType()</div>

    The output of the above is:

    Number: 1072 Type: System.Int32

    So, I tried combining the above:

            int number3 = int.Parse(@item.Attribute("link").Value.ToString());
            dynamic testNode2 = new DynamicNode(number3);
            <div> @testNode2.captionUrl.url</div>

    But, the above code gives me the same error,  I get an error "'string' does not contain a definition for 'url'"

    I just don't get it, if I change the code to the following:

            int number3 = 1072;
            dynamic testNode2 = new DynamicNode(number3);
            <div> @testNode2.captionUrl.url</div>

    It works without error, but as soon as I dynamically set the nodeId, if errors!!

    Anyone got any suggestions?

    Thanks

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 31, 2012 @ 12:35
    Jeroen Breuer
    0

    Hmm that is strange. What version of Umbraco are you using? DynamicXml has been changed a couple of times.

    Jeroen

  • Danny Winbourne 33 posts 54 karma points
    Jan 31, 2012 @ 12:38
    Danny Winbourne
    0

    I am using version 4.7.1, which is one down from the very latest I beleive. (which is 4.7.1.1 if I am not mistaken)

    Cheers
    Danny 

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 31, 2012 @ 12:45
    Jeroen Breuer
    0

    Could you please upgrade to 4.7.1.1 to see if that fixed it? It's a patch release so you can just update /bin, /umbraco and /umbraco_client

    Jeroen

  • Danny Winbourne 33 posts 54 karma points
    Jan 31, 2012 @ 13:40
    Danny Winbourne
    0

    OK, I updated, but I am still getting an error.

    It now doesn't tell me what the error is. It just says "Error loading MacroEngine script (file: Carousel.cshtml)"

    That is annoying in it itself, as I can't now easily debug macro scripts! 

     

     

     

     

     

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 31, 2012 @ 13:57
    Jeroen Breuer
    0

    If you have debugging enabled you can add ?umbDebugShowTrace=true to the url of your page to show the trace which will show the error.

    Jeroen

  • Danny Winbourne 33 posts 54 karma points
    Jan 31, 2012 @ 14:01
    Danny Winbourne
    0

    OK, I can confirm that it is the same error was before:

    I am not sure why it saying 'string' does not contain, as it should be dynamic XML at this point?

    Error Loading Razor Script (file: Carousel) 'string' does not contain a definition for 'url'    at CallSite.Target(Closure , CallSite , Object )
      at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
      at CallSite.Target(Closure , CallSite , Object )
      at ASP._Page_macroScripts_Carousel_cshtml.Execute() in g:\Sites\xxx-xx\xxxx-xxxx\macroScripts\Carousel.cshtml:line 22
      at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
      at System.Web.WebPages.WebPage.ExecutePageHierarchy()
      at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
      at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
      at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)

  • Danny Winbourne 33 posts 54 karma points
    Jan 31, 2012 @ 15:30
    Danny Winbourne
    0

    I have found a work around that means I can continue, but I think there may be a bug somewhere here, as I can't see why the above methods shouldn't work.

    The following however works for me:

     

            DynamicNode xmlNode = new DynamicNode(int.Parse(@item.Attribute("link").Value.ToString()));
            dynamic urlXml = new DynamicXml("" + xmlNode.GetProperty("captionUrl").Value.Replace("-", "") + "");

     

    I then have to check to see if there are any decendents, and output the result

     

    @if (urlXml.Descendants().Count > 0)
    {
    @urlXml.Descendants()[0].url

     

    Note, I have to wrap the XML into root nodes, as the URL Picker doesn't have a root, and I also needed to replace properties that had "-" in them, as these were not accessible with the razer syntax

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 31, 2012 @ 15:39
    Jeroen Breuer
    0

    Hmm I see you are replacing the stripe (-). This is a bug which should have been fixed in Umbraco 4.7.1 http://umbraco.codeplex.com/workitem/30290

    Might also be related to this: http://umbraco.codeplex.com/workitem/30680

    Not sure if this info is helpful.

    Jeroen

  • Danny Winbourne 33 posts 54 karma points
    Jan 31, 2012 @ 15:52
    Danny Winbourne
    0

    Right, issue solved..

    I resaved the pages that were added to the releated link collection, and the error went away.

    I am only guessing that it hadn't saved correctly to the database?

Please Sign in or register to post replies

Write your reply to:

Draft