ASP.NET MVC Razor helpers are a great way of reducing duplicated code by containing code snippets in a View which can then be called multiple times.


@helper DisplayGreeting(string name)
    <span>Hello @name</span>

However what if you wish to call this same helper on another View?

In which case the helper can be stored in a seperate View in the “App_Code” folder.

For example create a new View in the “App_Code” folder called “MyHelpers.cshtml”:


Move the helper code into this file:


Then the helper can be called from the previous view by using MyHelpers.DisplayGreeting:


This way any View within the same ASP.NET MVC Application can then make use of this helper.