Skip to Content
Introducing .NET 4.0: with Visual Studio 2010
book

Introducing .NET 4.0: with Visual Studio 2010

by Alex Mackey
February 2010
Beginner content levelBeginner
400 pages
11h 13m
English
Apress
Content preview from Introducing .NET 4.0: with Visual Studio 2010

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.

  1. Open the file ~/Controllers/FilmController.cs.

  2. 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();
     }
  3. 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());
    }
  4. Right-click the ~/Views/Film directory, and select Add New ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

ASP.NET 3.5 For Dummies®

ASP.NET 3.5 For Dummies®

Ken Cox
ASP.NET 4 Unleashed

ASP.NET 4 Unleashed

Stephen Walther, Kevin Hoffman, Nate Dudek

Publisher Resources

ISBN: 9781430224556Purchase book