Copied to clipboard

Flag this post as spam?

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


  • Saied 349 posts 674 karma points
    Sep 02, 2015 @ 16:38
    Saied
    0

    Is this the best way to filter child nodes?

    I have a Products node and under that I have Product nodes.

    I have an Action method on a Surface controller that I post search values to and I pass those search values to a Partial view to render results. What I decided to do was add a Multiple Dropdown list with car makes, so when the content manager creates a new Product, they can associate the Product with different car makes.

    Currently, I am doing all this logic in the view like so:

    @model ProductFilterModel
    @{
        Layout = "../Master.cshtml";
    }
    
    @{
        var products = Model.Content.Children.ToList();
    
        var filteredProducts = products.Where(x=>x.GetPropertyValue<string>("make").Contains(@Model.Make));
    }
    
    @foreach (var product in filteredProducts)
    {
        <div style="border:1px solid black;">
        <h1>@product.Name</h1>
        <a href="@product.Url">The link to the @product.Name node</a>
        <h1 style="font-size:42px;">@product.GetPropertyValue("make")</h1>
            </div>
    }
    

    Is there a cleaner/better/preferred way of doing stuff like this?

    Also, my products are stored in an external database. Would it be better to create a table on my external database side with the product id's that link to the templates and when the user searches, I can compare the id in the query results to the child node ids and only return those to be rendered. This way, I don't think I would have to have properties of make, model, engine, year.

    Trying to see the advantages/disadvantages of both?

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Sep 03, 2015 @ 10:04
    Alex Skrypnyk
    0

    Hi Saied,

    For better performance you can cache filtered product list for some time. I think it would be better. Or cache all partial view.

  • 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