Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
A common need is to generate the same block of HTML repeatedly in a view. Duplicating the same HTML elements and Razor tags over and over again is tedious and prone to errors. Furthermore, if you need to make changes, you must do so in multiple places. Fortunately, the MVC Framework provides a mechanism for solving the problem, called HTML helpers. In this section, we'll show you how to create the two different kinds of HTML helpers that are available and demonstrate the built-in helpers that are included with the MVC Framework.
The most direct way to create a helper is to do so in the view, using the Razor @helper tag. Listing 15-19 contains an example.