Copied to clipboard

Flag this post as spam?

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


  • Tim C 161 posts 528 karma points
    May 23, 2016 @ 12:50
    Tim C
    0

    cast System.Collections.Generic.List<Umbraco.Web.Models.DynamicPublishedContent> to Umbraco.Web.Models.DynamicPublishedContentList

    I am trying to use a single variable for either an Examine search :

    var Query = (!string.IsNullOrEmpty(Request.QueryString["query"])?Request.QueryString["query"]:"");
    
    var listItems = @CurrentPage
                    .Search(Request.QueryString["query"]);
    

    or (depending on the parameters) a node.Children - but concatenating several

    var rootnodeIdsAR = rootnodeIds.Split(',');
    
        var listItems = getnodeList(rootnodeIdsAR[0]).ToList(); 
    
    
        for(var nl = 1; nl < rootnodeIdsAR.Length;nl++){
            var listItemstmp = getnodeList(rootnodeIdsAR[nl]);
            listItems = listItems.Concat(listItemstmp).ToList();
        }
    
    functions{
        public Umbraco.Web.Models.DynamicPublishedContentList getnodeList(string parentnodeId){
            var parentNode = Umbraco.Content(parentnodeId);
            Umbraco.Web.Models.DynamicPublishedContentList nList;
            nList= parentNode.Children
                .Where("Visible");
            return nList;
        }
    }
    

    Each of the abover works in isolation (ie by letting var listItems handle the type casting) but if I try to get them to work in the same view

    ie

    if(Query!=""){
        listItems = @CurrentPage
                        .Search(Query);
    }else{
            listItems = getnodeList(rootnodeIdsAR[0]).ToList(); 
    
    
            for(var nl = 1; nl < rootnodeIdsAR.Length;nl++){
                var listItemstmp = getnodeList(rootnodeIdsAR[nl]);
                listItems = listItems.Concat(listItemstmp).ToList();
            }
    
    }
    

    then I have a problem as I can't declare listItems twice.

    I can't seem to be able to cast one as the other.

    The reason for the use of a single variable is so I can use the listItems later in various parts of the code)

    Not sure if this possible : maybe I'm trying to be too clever!

  • Tim C 161 posts 528 karma points
    May 24, 2016 @ 04:09
    Tim C
    0

    Solved

    System.Collections.Generic.IEnumerable

Please Sign in or register to post replies

Write your reply to:

Draft