The first part of the site that we'll implement will be the
Product Listing URL (/Products/Category/[CategoryId]):
Figure 8

We'll implement this functionality using the
"Category" action on our ProductsController class. We'll use
our LINQ to SQL DataContext class, and the GetCategoryById helper method we
added to it, to retrieve a Category object that represents the particular
category indicated by the URL (for example: /Products/Category/3). We'll
then pass the Category object to the "List" view to render a response
from it:
Figure 9

When implementing our List view we'll first update our
page's code-behind to derive from ViewPage<Category> so that our page's
ViewData property will be typed to the Category object that was passed by our
Controller (Part 3 discusses this more):
Figure 10

We'll then implement our List.aspx like below:
Figure 11

The above view renders the Category name at the top of the
page, and then renders a bulleted list of the Products within the
category.
Next to each product in the bulleted list is an
"Edit" link. We are using the Html.ActionLink helper method
that I discussed in Part 2 to render a HTML hyperlink (for example: <a
href="/Products/Edit/4">Edit</a>) that when pressed will navigate
the user to the "Edit" action. We are also then using the
Html.ActionLink helper method again at the bottom of the page to render a <a
href="/Products/New">Add New Product</a> link that when
pressed will navigate the user to the "New" action.
When we visit the /Products/Category/1 URL and do a
view-source in the browser, you'll notice that our ASP.NET MVC application has
emitted very clean HTML and URL markup:
Figure 12
