13.8. Displaying a List of Data
You will now create a page to display a list of all the films. You need to add this functionality to the controller.
Open the file ~/Controllers/FilmController.cs.
Add the following code at the top of the class to get an instance of the FilmRepository:
BobsMoviesMVC.Models.IFilmRepository filmRepository; public FilmController() { filmRepository = new BobsMoviesMVC.Models.FilmRepository(); }
You might think there are easier ways of doing this (and you would be right), but this sets you up nicely for testing the application. Now add the following action to retrieve a list of all the films:
public ActionResult All() { return View(filmRepository.GetAll()); }
Right-click the ~/Views/Film directory, and select Add New ...
Get Introducing .NET 4.0: with Visual Studio 2010 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.