List groups
List groups are flexible components that either display simple lists of elements or can be combined with other elements to create complex lists with custom content. As an example, we'll create a sample search page that will display the search results in a Bootstrap list group.
Start by completing the following steps:
- Add a new controller called
SearchController.csto your project. - Change the
Indexaction to the following:public IActionResult Index(string query) { ViewBag.SearchQuery = query; var products = GetProducts(); if (!string.IsNullOrEmpty(query)) { var results = products.Where(p => p.Name.Contains(query)); return View(results); } return View(products); } - The preceding code retrieves a list of all products using the
GetProductsmethod. It will then filter the list of products if thequeryparameter contains a value and returns the...