Copied to clipboard

Flag this post as spam?

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


  • Søren Mastrup 122 posts 564 karma points c-trib
    Feb 08, 2014 @ 00:47
    Søren Mastrup
    0

    Hiding items that returns false in one or more properties

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{  
        var Brand = @Request.Params["brand"];
        var Price = @Request.Params["price"];
    }
    
    @foreach(var item in CurrentPage.Children){
        <p>@item.Name<br />
            //The following outputs True or False depending on values defined in my address bar.
            //(Just to see what is happening)
            @item.brand.Contains("" + Brand + "")<br />
            @item.pris.Contains("" + Price + "")
        </p>
    }
    

    In the code above I only want to show the item if all values are True. If one or more values returns False, the item should not be shown. I have tried to make an if-sentence inside my foreach, using GetPropertyValue, but haven't got it to work.

    Can anyone give me some pointers on how to assemble this correct?

  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 08, 2014 @ 18:30
    Fuji Kusaka
    0

    Hi Soren,

    Have a look at the following post. It might help you to get this working.

    http://our.umbraco.org/documentation/Reference/Mvc/querying

    For properties

    http://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors 

     

    //Fuji

     

     

     

     

     

     

     

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Feb 10, 2014 @ 10:47
    Jeavon Leopold
    0

    Hi Soren,

    How about something like this?

    @{
        var brand = string.IsNullOrEmpty(Request.Params["brand"]) ? string.Empty : Request.Params["brand"];
        var price = string.IsNullOrEmpty(Request.Params["price"]) ? string.Empty : Request.Params["price"];
    
        foreach (var item in CurrentPage.Children.Where("brand.Contains(@0) && pris.Contains(@1)", brand, price))
        {
            <p>@item.Name</p>
        }
    }
    

    Jeavon

  • Søren Mastrup 122 posts 564 karma points c-trib
    Feb 12, 2014 @ 13:34
    Søren Mastrup
    0

    Thanks for the inputs guys!

Please Sign in or register to post replies

Write your reply to:

Draft