Problem

How to use Tag Helpers in ASP.NET Core MVC to simplify the creation of data entry forms.

Solution

In an empty project, update the Startup class to add the services and middleware for MVC.

Add a Controller with these action methods.

Add a _ViewImports.cshtml page in Views folder. Add a directive to import the tag helpers.

Add a model to use on the data entry screen.

Add a Razor page (Index.cshtml).

Discussion

Tag Helpers help generate HTML by attaching attributes to the existing HTML elements or by creating new elements. Although they look like HTML elements and attributes, Tag Helpers are processed by Razor (server-side).

I like to think of Tag Helpers as C# extensions methods, i.e., they allow us to attach some extra behavior to the existing classes.

The sample project shows the usage of various tag helpers that can help in creating data entry forms. I have outlined the key information about these below:

Form

Input & Text Area

Label

Validation

Select

Anchor

Source Code

GitHub