Using HTML links to execute controller action methods.
It’s common to have a requirement that a controller’s action method be called from several different pages within a site.
Also, this knowledge usually won’t be entirely flushed out at the beginning of project development.
To compensate for this need, MVC 3 provides a nice overloaded Html.ActionLink() that allows the developer to place a link calling any controller action desired.
To illustrate this function, I’ll begin with my Anonymous Types article where I illustrate the use of a new .NET 4.0 feature.
This article fully describes the code involved and resulting HTML you will see shortly.
Moving on from the details of Anonymous Types, I’ll illustrate how to use the Html.ActionLink() method.
This method takes as parameters (one of the overloaded version): text to displayed as a link, the name of the action method, and the controller name.
In this example, I’ll call my AnonymousTypes controller’s Index action method.
By clicking the homepage “Anonymous Types” link, I see the results of my work.