Copied to clipboard

Flag this post as spam?

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


  • Zakhar 171 posts 397 karma points
    Oct 08, 2012 @ 12:31
    Zakhar
    0

    UComment and comments display order - razor

    Hi guys,

    I'm using UComment on my site and display the list of comments using razor code similar to the one shown here: http://our.umbraco.org/projects/collaboration/ucomment/using-ucomment/19347-UComment-and-Razor

    The problem with it is that it uses XPathNodeIterator which gets all comments and displays them in the way that old comments are on the top and new comments are at the bottom. I (and I guess most of others) want to display latest comments on top.

    Is it possible to iterate the collection backwards? Is there a way to sort comments somehow?

    Thanks,

    Zakhar.

  • Sean Håkansson 61 posts 177 karma points
    May 31, 2013 @ 11:36
    Sean HÃ¥kansson
    0

    Hi Zakhar, 

    I had the same problem, the solution I found was to use the XPathNavigator & Expression.

     

    var title = Model.Name;
    XPathNodeIterator nodesroot = XsltLibrary.GetCommentsForNode(HttpContext.Current.Request.RawUrl.GetHashCode());
    XPathNavigator curnavigator = nodesroot.Current;
    XPathExpression nodesexpr = XPathExpression.Compile("//comment");
    nodesexpr.AddSort("@created", XmlSortOrder.Descending, XmlCaseOrder.None, "", XmlDataType.Text); XPathNodeIterator nodes = curnavigator.Select(nodesexpr);
    int cnt = nodes.Count;

    Hope this helps you out.

  • 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