December 2018
Beginner to intermediate
668 pages
15h 30m
English
Back in the HomeController class, add an action method named ProductDetail, as shown in the following code:
public IActionResult ProductDetail(int? id) { if (!id.HasValue) { return NotFound("You must pass a product ID in the route, for example, /Home/ProductDetail/21"); } var model = db.Products.SingleOrDefault(p => p.ProductID == id); if (model == null) { return NotFound($"A product with the ID of {id} was not found."); } return View(model); // pass model to view }
Note the following:
Read now
Unlock full access