Microsoft 9GD00001 Computer Accessories User Manual


 
Chapter 9: Creating Web Applications with ASP.NET MVC 273
would be bad. Using Html.Encode prevents this from happening. The other Html helper
methods, such as ActionLink, already encode output, so you should use Html.Encode
whenever one of the other helpers isn’t used. Notice that the code for the foreach loop is
enclosed in <% and %> symbols so that it is treated as code and not markup.
Next, you’ll want to be able to navigate to the Customer List page from the main
menu, so open your MasterPage, Site.Master, and add the Customers ActionLink like this:
<ul id="menu">
<li><%= Html.ActionLink("Customers", "Index", "Customer")%></li>
<li><%= Html.ActionLink("Home", "Index", "Home")%></li>
<li><%= Html.ActionLink("About", "About", "Home")%></li>
</ul>
The parameters to the new ActionLink, from left to right, indicate that the text for
the anchor will be Customers, and ASP.NET will invoke the Index action method
on the CustomerController class when the user clicks the link. Figure 9-6 shows what
the Customer list looks like when the program runs.
Figure 9-6 Showing a list of objects