Try our conversational search powered by Generative AI!

Gathering Database data, paginate it and search bar in block with controller.


Hello :). I'm new with episerver and i have a task to implement block which have to get information from the database and visualize it (also paginate, and search with an input field). Any suggestions please :) ?

Sep 11, 2021 17:22

Hi, welcome to the platform.

You don't directly access the Optimizely CMS (formally Episerver) database, as standard you wouls retrive the content either one of 2 ways.

  1. The platform APIs. For this you use the IContentLoader . Here you can read about 2 of the core interfaces for working with content in the platform. All platform content inherits IContent (along with many other core interfaces and classes), the IContentLoader when injected in will give you the service for reading content. The IContentRepository inherits the IContentLoader but adds CRUD operations.
  2. A search provider. Depending on where your solution is/or will be hosted or what services you're paying for depends on this one. Search & Navigation (Formally Find) is the standard search platform that is uses and comes as part of the Optimizely DXP platform, so if you're hosting on there you can use that. If not you would usually either be using the Lucene based provider or replacing with something like ElasticSearch to index and search your content.

The different with 1 and 2 depends on what you're wanting to retrive. Commonly the search provider should be used for large search queries or queries with search parameters. This would include search pages, listings, related content and anything with groups of content. 1 and using the APIs is usage a lot when you are loading content within an instance of a block or page, or loading from references. Although the controllers page instances of the block/page as standard in the controllers.

In your scenario if you're trying to search, paginate and take an input field I would use the search provider you're using in your solution. This would be the following process

  1. Create block model
  2. Create controller (passes in block model)
  3. Create viewmodel for block
  4. Create view for block
  5. In Controller use the search API of choice to find content and populate your viewmodel passing it to the view.

All of this will be handled as per standard MVC.

If you're new to the platform I'd suggest installing the Alloy demo and getting familiar with how it works. there are examples of using search. You can install the lucence search or Search and Navigation (Find) and you can create a demo index for it here 

Edited, Sep 12, 2021 16:43
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.