Chapter 9: Creating Web Applications with ASP.NET MVC | 269 |
This will create a new Controller with several methods for working with Customer data. Listing
Displaying a Customer List
The first thing to do with customers is to display a list that will serve as a starting point for other operations. Listing
Listing 9-7 A Controller for displaying a list
C#:
public ActionResult Index()
{
var customers =
new CustomerRepository()
.GetCustomers();
return View(customers);
}
VB:
Function Index() As ActionResult
Dim custRep As New CustomerRepository
Dim customers As List(Of Customer)
customers = custRep.GetCustomers() Return View(customers)
End Function
Listing
To create the View,
The name of the View is Index, corresponding to the name of the action method invoking the View. Naming the View after the action method is the default behavior, but