More in this section

Forums / Developing with Sitefinity / Filter Custom Module Collection By URL

Filter Custom Module Collection By URL

4 posts, 1 answered
  1. Coty
    Coty avatar
    29 posts
    25 Aug 2006
    15 Feb 2013
    Link to this post

    This has to be an easy one...what am I doing wrong?

    I have a custom module, that I want to filter by the URL

    example URL:

    I have a usercontrol that loads on the page, I grab the filterstring from the URL:

    var myPartner = string.Empty;
    var param = Request.RequestContext.RouteData.Values["params"] as string[];
    myPartner = (string)param[0];

    Now I want to pull my "Partners" which is my custom module and filter by the filter string above.

    This is my query:

    var PartnersCollection = dynamicModuleManager.GetDataItems(partnerType).Where(p => p.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && p.UrlName == myPartner && p.GetValue<bool>("Active") == true);

    If I pull out "p.UrlName == myPartner" the query works fine and pulls all Partners.  I just want to filter by the auto generated URL that was created when the Partner was created.

    I tried these already:

    p.UrlName == myPartner 

    p.SystemUrl == myPartner

    p.Urls[0].Url == myPartner

    The first one pulls 0 records and the last 2 cause errors.  What am I doing wrong?



  2. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    18 Feb 2004
    15 Feb 2013 in reply to Coty
    Link to this post

    Hey Coty,

    I always use this code to get the item from the url:

    var urlParameterString = System.Web.UI.ControlExtensions.GetUrlParameterString(this, true).Substring(1);
    if (urlParameterString == "undefined")
    // Get the Lawyer item
    var dynamicModuleManager = DynamicModuleManager.GetManager();
    var lawyerType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Lawyers.Lawyer");
    var lawyer = dynamicModuleManager.GetDataItems(lawyerType).FirstOrDefault(x => x.Status == ContentLifecycleStatus.Live && x.UrlName == urlParameterString);

    Kind regards,

  3. Coty
    Coty avatar
    29 posts
    25 Aug 2006
    15 Feb 2013 in reply to Daniel Plomp
    Link to this post

    Thanks for the response.

    I copied your code and I'm still returning Null.  Its the UrlName Property that is making it not work. If I go to Content > Partners (that is my custom module) and look at the URL at the bottom it matches the variable I am passing in so I am not sure why it's not working.

    Anyone know of any reason the UrlName query above wouldn't return results?

  4. Coty
    Coty avatar
    29 posts
    25 Aug 2006
    18 Feb 2013 in reply to Coty
    Link to this post

    Hey there, I figured out my issue.  Actually both our code snippets work above.  I am going to add .FirrstOrDefault() to mine though since I am just pulling one item.

    This was my final query:

    DynamicContent partner = dynamicModuleManager.GetDataItems(partnerType).Where(p => p.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && p.UrlName == myPartner && p.GetValue<bool>("Active") == true).FirstOrDefault();

    My issue ended up being a carriage return was attached to my variable so it wasn't matching anything.  Thanks for your help!


4 posts, 1 answered