Copied to clipboard

Flag this post as spam?

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


  • Vincent 75 posts 98 karma points
    Jul 20, 2011 @ 20:30
    Vincent
    0

    /base not working wit array

    Hi,

    I have a method that return an Array of Document in my RestExtension and it's not working, anyone have an idea?

    [RestExtensionMethod]
            public static Document[] HeadChildren()
            {
                var d = new Document(NodeId);
                return Document.GetChildrenForTree(NodeId);
            }

    The result is : <value>umbraco.cms.businesslogic.web.Document[]</value>

    I think it's a problem with the serialization of an array.

    Thanks a lot!

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 20, 2011 @ 21:39
    Dirk De Grave
    0

    Hi Vincent,

    Not sure if that would make a difference, but have you tried setting returnXml=false on the RestExtensionMethod attribute. If that doesn't work, I'd look into returning a string as the result of the function call (for example, return a json representation of your document array, which you can easily consume from jquery)

     

    Cheers,

    /Dirk 

  • Vincent 75 posts 98 karma points
    Jul 20, 2011 @ 22:36
    Vincent
    0

    I already try that, I decided to go with JSON and I don't have any problem now, thanks!

     

    [RestExtensionMethod(returnXml = false)]

            public static string BuildMainMenu()

            {

                return BuildMenu("showInMainMenu");

            }

     

            private static string BuildMenu(string property)

            {

                var headNode = new Document(NodeId);

                var menuElems = new List<SerializableUmbracoMenuElem>();

                var serializer = new JavaScriptSerializer();

     

                if (headNode.getProperty(property).Value.ToString() == "1")

                {

                    menuElems.Add(FillUmbracoData(headNode));

                }

     

                foreach (var topMenuNode in headNode.Children)

                {

                    if (topMenuNode.getProperty(property).Value.ToString() == "1")

                    {

                        menuElems.Add(FillUmbracoData(topMenuNode));

                    }

                }

                return serializer.Serialize(menuElems);

            }

     

Please Sign in or register to post replies

Write your reply to:

Draft