Copied to clipboard

Flag this post as spam?

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


  • Toni Becker 146 posts 425 karma points
    Jul 19, 2011 @ 17:34
    Toni Becker
    0

    Get Paramter to use with .Where and contains

    Somebody have an idea how to solve this.

    @{
    //retrive all Posts
    dynamic artikelListe = Model.AncestorOrSelf(1).DescendantsOrSelf("uBlogsyPost");
    string catSelect = @Parameter.kategorieName; <---- This is my Macroparameter i need to input the Categoryname
    }  
                                      
    @foreach(dynamic n in artikelListe.Where("uBlogsyPostCategories.Contains(\"Nachtleben\")").Take(4).OrderBy("uBlogsyPostDate desc"))

    Code works this way, but it is not working with dynamic n in articleList.Where("uBlogsyPostCategories.Contains(@catSelect)......

    not working too :):
    articleList.Where("uBlogsyPostCategories == catSelect").....

     

    Any Ideas. ????

  • Alex 78 posts 136 karma points
    Jul 19, 2011 @ 17:44
    Alex
    0

    Hey Toni,

    Try using String.Format to inject your variable value into the string. Something like this:

    Where(String.Format("uBlogsyPostCategories == {0}", catSelect))

     

  • Toni Becker 146 posts 425 karma points
    Jul 19, 2011 @ 18:05
    Toni Becker
    0

    nope nothings happen, no html rendering :/

  • Toni Becker 146 posts 425 karma points
    Jul 19, 2011 @ 18:14
    Toni Becker
    0

    If i try this

    @foreach(dynamic n in artikelListe.Where("uBlogsyPostCategories.Contains(catSelect)").Take(4).OrderBy("uBlogsyPostDate desc"))

    this error is showing up:

    Expression of type 'System.Func`2[umbraco.MacroEngines.DynamicNode,System.Object]' cannot be used for parameter of type 'System.String' of method 'Boolean Contains(System.String)'

  • Toni Becker 146 posts 425 karma points
    Jul 20, 2011 @ 09:26
    Toni Becker
    0

    No one has an idea? I think should be possible somehow.

  • Alex 78 posts 136 karma points
    Jul 20, 2011 @ 09:44
    Alex
    0

    Slight error in my previous post, you need to surround the variable value in escaped double quotes, like this:

    Where(String.Format("uBlogsyPostCategories == \"{0}\"", catSelect))

     

  • Toni Becker 146 posts 425 karma points
    Jul 20, 2011 @ 09:46
    Toni Becker
    0

    will test it out and give you feedback in 5 mins. Thanks so long, hope this will work :)

  • Toni Becker 146 posts 425 karma points
    Jul 20, 2011 @ 10:07
    Toni Becker
    0

    worked, thanks to alex

  • 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