Querying a database and using display templates
Let's create a new action method that can have a query string parameter passed to it and use that to query the Northwind database for products that cost more than a specified price.
In previous examples, we defined a view model that contained properties for every value that needed to be rendered in the view. In this example, there will be two values: a list of products and the price the visitor entered. To avoid having to define a class or record for the view model, we will pass the list of products as the model and store the maximum price in the ViewData collection.
Let's implement this feature:
- In
HomeController, import theMicrosoft.EntityFrameworkCorenamespace. We need this to add theIncludeextension method so that we can include related entities, as you learned in Chapter 10, Working with Data Using Entity Framework Core. - Add a new action method, as shown in the following code:
public...