Passing parameters using a query string

In the HomeController class, import the Microsoft.EntityFrameworkCore namespace. We need this to add the Include extension method so that we can include related entities.

Add a new action method, as shown in the following code:

public IActionResult ProductsThatCostMoreThan(decimal? price) {    if (!price.HasValue)    {       return NotFound("You must pass a product price in the query      string, for example, /Home/ProductsThatCostMoreThan?price=50");    }    var model = db.Products.Include(p => p.Category).Include(    p => p.Supplier).Where(p => p.UnitPrice > price).ToArray();    if (model.Count() == 0)    {       return NotFound($"No products cost more than {price:C}.");    }  ViewData["MaxPrice"] = price.Value.ToString("C");  ...

Get C# 7.1 and .NET Core 2.0 – Modern Cross-Platform Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.