December 2018
Beginner to intermediate
668 pages
15h 30m
English
Open the HomeController class.
Import the Packt.CS7 namespace.
Add a field to store a reference to a Northwind instance, and initialize it in a constructor, as shown in the following code:
private Northwind db; public HomeController(Northwind injectedContext) { db = injectedContext; }
Modify the contents of the Index action method, as shown in the following code:
var model = new HomeIndexViewModel { VisitorCount = (new Random()).Next(1, 1001), Categories = db.Categories.ToList(), Products = db.Products.ToList() }; return View(model); // pass model to view
Read now
Unlock full access