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.
- Right-click at View method > Add View.
- Just use a simple template.
- Then, Add.
- Notice there is a new class with Index in name.