Adding a List Controller and View

We don't have landing page to our website. Now, we want to make it.

First, go back to your repository class. Add a function get all comic books.

public ComicBook[] GetComicBooks()
{
    return _comicBooks;
}

Then, in our Controller class, we create a function called Index().

public ActionResult Index()
{
    var comicBooks = _comicBookRepository.GetComicBooks();

    return View(comicBooks);
}

Remember, passing an array into the View method will make our array available via the view's model property.

So, we need to add a View class for this function. Different way to add a View class presented below.

  1. Right-click at View method > Add View.
  2. Just use a simple template.
  3. Then, Add.
  4. Notice there is a new class with Index in name.

results matching ""

    No results matching ""