---
title: Providing product filters on MVC sites
related:
  - https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-on-line-stores-in-mvc/displaying-product-listings-on-mvc-sites.md
  - https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-on-line-stores-in-mvc.md
  - https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications.md
  - https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/starting-with-mvc-development/installing-kentico-integration-packages.md
  - https://docs.kentico.com/k11/e-commerce-features/managing-your-store/products.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

When you create a [product listing](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-on-line-stores-in-mvc/displaying-product-listings-on-mvc-sites.md) in your MVC application to display a list of offered [products](https://docs.kentico.com/k11/e-commerce-features/managing-your-store/products.md), you may want to filter products based on its properties. For example, if you sell notebooks, you may filter them based on their [manufacturers](https://docs.kentico.com/k11/e-commerce-features/managing-your-store/products/managing-brands-and-manufacturers.md), screen resolutions, mobile internet modules and many other attributes.

> **Info:** The [Kentico.Ecommerceintegration package](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/starting-with-mvc-development/installing-kentico-integration-packages.md) currently supports only products consisting of a [page](https://docs.kentico.com/k11/managing-website-content/working-with-pages.md) and an SKU object (the default product setting). The [stand-alone SKU product mode](https://docs.kentico.com/k11/e-commerce-features/managing-your-store/products/managing-stand-alone-skus.md) is not supported in MVC.

You can filter different attributes of products. Different processes follows when filtering:

- [Based on page properties](#filtering-based-on-page-properties)
- [Based on SKU properties of a primitive type or string](#filtering-based-on-sku-properties-of-a-primitive-type-or-string) (typically, Boolean, byte, integer or string variables)
- [Based on SKU properties from another database table](#filtering-based-on-sku-properties-from-another-database-table) (typically, [public statuses](https://docs.kentico.com/k11/e-commerce-features/managing-your-store/products/product-statuses.md) or manufacturers)

> **Tip:** **Tip**: To view the full code of a functional example directly in Visual Studio, download the [Kentico MVC solution](https://github.com/Kentico/Mvc) from GitHub and inspect the **LearningKit** project. You can also run the Learning Kit website after connecting the project to a Kentico database.

## Filtering based on page properties

Page properties are available in [itsTreeNodeobject and its coupled data](https://docs.kentico.com/k11/custom-development/working-with-pages-in-the-api/page-database-structure.md).

To filter products based on page properties:

1. Open your MVC application in Visual Studio.
2. Modify a controller that processes the product listing with a filter:
   1. Initialize the **ShoppingService** and **PricingService** from the [Kentico.Ecommerceintegration package](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/starting-with-mvc-development/installing-kentico-integration-packages.md) if they are not already.

      > **Tip:** We recommend using a [dependency injection container](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/initializing-kentico-services-with-dependency-injection.md) to initialize service instances. When configuring the lifetime scope for _ShoppingService_ and _PricingService_, create a separate instance for each request.

      ```csharp

                  shoppingService = new ShoppingService();
                  pricingService = new PricingService();


      ```
   2. Add a POST controller's action that processes the filter information. For example, the following code loads products based on a boolean check box (the _LPTWithFeature_ represents a page type's field):

      ```csharp

                  // Creates a view model that consists of information
                  // whether the 'LPTWithFeature' is selected and a list of products
                  ProductFilterViewModel filteredModel = new ProductFilterViewModel
                  {
                      LPTWithFeature = model.LPTWithFeature,
                      FilteredProducts = LoadProducts(GetWithFeatureWhereCondition(model))
                  };

                  return View(filteredModel);


      ```
   3. Create a where condition that limits the set of products. For example, for a check box (the _GetWithFeatureWhereCondition_ method from the previous example):

      ```csharp

                  // Initializes a new where condition
                  WhereCondition withFeatureWhere = new WhereCondition();

                  // If the feature is selected, sets the where condition
                  if (model.LPTWithFeature)
                  {
                      withFeatureWhere.WhereTrue("LPTWithFeature");
                  }


      ```
   4. Create a method that loads products based on the where condition.
3. Create a view and models based on your filter.

The filter now loads products that fulfill the condition specified by the visitor.

## Filtering based on SKU properties of a primitive type or string

SKU properties are available in the _COM\_SKU_ database table. In this subsection, you can learn about filtering based on SKU data that carry the full meaning in the database table. For properties that are only foreign keys from a different table, see [Filtering based on SKU properties from another database table](#filtering-based-on-sku-properties-from-another-database-table).

To filter products based on the specified SKU properties:

1. Open your MVC application in Visual Studio.
2. Modify a controller that processes the product listing with a filter:
   1. Initialize the **ShoppingService** and **PricingService** from the [Kentico.Ecommerceintegration package](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/starting-with-mvc-development/installing-kentico-integration-packages.md) if they are not already.

      > **Tip:** We recommend using a [dependency injection container](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/initializing-kentico-services-with-dependency-injection.md) to initialize service instances. When configuring the lifetime scope for _ShoppingService_ and _PricingService_, create a shared instance (singleton) for all requests.

      ```csharp

                  shoppingService = new ShoppingService();
                  pricingService = new PricingService();


      ```
   2. Add a POST controller's action that processes the filter information. For example, the following code loads products based on a price range from–to (the _SKUPrice_ column from the product's SKU database table):

      ```csharp

                  // Creates a view model that consists of the entered price range
                  // and a list of products
                  ProductFilterViewModel filteredModel = new ProductFilterViewModel
                  {
                      PriceFrom = model.PriceFrom,
                      PriceTo = model.PriceTo,
                      FilteredProducts = LoadProducts(GetPriceWhereCondition(model))
                  };

                  return View(filteredModel);


      ```
   3. Create a where condition that limits the set of products. For example, for two text boxes for a from–to range (the _GetPriceWhereCondition_ method from the previous example):

      ```csharp

                  // Initializes a new where condition
                  WhereCondition priceWhere = new WhereCondition();

                  // Sets the price where condition based on the model's values and limited by the price from-to range
                  if (Constrain(model.PriceFrom, model.PriceTo))
                  {
                      priceWhere.WhereGreaterOrEquals("SKUPrice", model.PriceFrom)
                          .And().WhereLessOrEquals("SKUPrice", model.PriceTo);
                  }


      ```
   4. Create a method that loads products based on the where condition.
3. Create a view and models based on your filter.

The filter now loads products that fulfill the condition specified by the visitor.

## Filtering based on SKU properties from another database table

SKU properties are available in the _COM\_SKU_ database table. In this subsection, you can learn about filtering based on linked SKU data from another database table. For properties that carry the full meaning in the _COM\_SKU_ table, see [Filtering based on SKU properties of a primitive type or string](#filtering-based-on-sku-properties-of-a-primitive-type-or-string).

To filter products based on the specified linked properties:

1. Open your MVC application in Visual Studio.
2. Modify a controller that processes the product listing with a filter:
   1. Initialize the **ShoppingService** and **PricingService** from the [Kentico.Ecommerceintegration package](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/starting-with-mvc-development/installing-kentico-integration-packages.md) if they are not already.

      > **Tip:** We recommend using a [dependency injection container](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/initializing-kentico-services-with-dependency-injection.md) to initialize service instances. When configuring the lifetime scope for _ShoppingService_ and _PricingService_, create a shared instance (singleton) for all requests.

      ```csharp

                  shoppingService = new ShoppingService();
                  pricingService = new PricingService();


      ```
   2. In the GET controller's action that displays the listing with the filter, you need to get all objects to display the filter. For example, the following code gets all manufacturers' names and loads all products of the product page type:

      ```csharp

                  // Creates a view model that consists of all foreign objects (manufacturers) related to the products
                  // and a list of products that will be filtered
                  ProductFilterViewModel model = new ProductFilterViewModel
                  {
                      Manufacturers = GetManufacturers(),
                      FilteredProducts = LoadProducts()
                  };

                  return View(model);


      ```
   3. Add a POST controller's action that processes the filter information. For example, the following code loads products based on selected manufacturers' display names):

      ```csharp

                  // Creates a view model that consists of all foreign objects (manufacturers) related to the products
                  // and a list of products that will be filtered with their selected state
                  ProductFilterViewModel filteredModel = new ProductFilterViewModel
                  {
                      Manufacturers = model.Manufacturers,
                      FilteredProducts = LoadProducts(GetManufacturersWhereCondition(model))
                  };

                  return View(filteredModel);


      ```
   4. Create a method that loads the foreign objects. For example, load the objects with an [object query](https://docs.kentico.com/k11/developing-websites/loading-and-displaying-data-on-websites/loading-data-using-custom-queries.md).
   5. Create a where condition that limits the set of products. For example, for a check box (the _GetManufacturersWhereCondition_ method from the previous example):

      ```csharp

                  // Initializes a new where condition
                  WhereCondition manufacturersWhere = new WhereCondition();

                  // Gets a list of strings representing display names of selected manufacturers
                  List<string> selectedManufacturersIds = GetSelectedManufacturersIds(model);

                  // If any manufacturer is selected, sets the where condition
                  if (selectedManufacturersIds.Any())
                  {
                      manufacturersWhere.WhereIn("SKUManufacturerID", selectedManufacturersIds);
                  }


      ```
   6. Create a method that loads products based on the where condition.
3. Create a view and models based on your filter.

The filter now loads products that fulfill the condition specified by the visitor.
