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?
Is this the best way to filter child nodes?
I have a
Products
node and under that I haveProduct
nodes.I have an
Action
method on aSurface 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 aMultiple 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:
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?
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.
is working on a reply...