MVC Music Store Tutorial v2.0 – http://mvcmusicstore.codeplex.com – Tutorial under Creative Commons Attribution 3.0 License
Page 36
When we run the application and browse to /Store, we see that both the count and list of Genres is
displayed.
Adding Links between pages
Our /Store URL that lists Genres currently lists the Genre names simply as plain text. Let’s change this so
that instead of plain text we instead have the Genre names link to the appropriate /Store/Browse URL, so
that clicking on a music genre like “Disco” will navigate to the /Store/Browse?genre=Disco URL. We could
update our \Views\Store\Index.cshtml View template to output these links using code like below:
<ul>
@foreach (var genre in Model)
{
<li><a href="/Store/
[email protected]">@genre.Name</a></li>
}
</ul>
That works, but it could lead to trouble later since it relies on a hardcoded string. For instance, if we
wanted to rename the Controller, we’d need to search through our code looking for links that need to be
updated.
An alternative approach we can use is to take advantage of an HTML Helper method. ASP.NET MVC
includes HTML Helper methods which are available from our View template code to perform a variety of