Creating HTML Helpers using static methods

The simplest way to create a helper in ASP.NET MVC used to be the @helper directive. Unfortunately, the @helper directive was removed from the new ASP.NET MVC Core, since it imposed too many restrictions on the other Razor features.

Fortunately, we're still able to create an HTML Helper using static method by completing the following steps:

  1. Create a new folder called Helpers inside the root folder of your project.
  2. Add a new class to this folder called Enums.cs. This file will contain all the enumerators for our project.
  3. Add the following code to the Enums.cs file:
            public class Enums        {        public enum ButtonStyle        {        Default,        Primary,        Secondary,        Success,        ...

Get Bootstrap for ASP.NET MVC - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.