O'Reilly logo

Applied ASP.NET 4 in Context by Adam Freeman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating an External Helper Method

Chapter 25 showed you how to use the @helper tag to create an internal helper. These are a useful way to avoid repetition, but they can be used only in the view in which they are defined, and they have a tendency to take over a view if they involve any significant amount of code.

The alternative is to create an external helper, which takes the form of a C# extension method. Listing 26-1 shows an example of an external helper that I have placed in a class called ExternalHelpers in the Infrastructure project folder. The MVC framework contains a set of built-in helper methods that cover most common requirements, but understanding how to build your own helps put everything in context.

Tip Helper methods are intended ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required