How it works...

Let's see, in detail, the static HTMLHelpers extension methods. They always return an IHtmlContent (an HtmlString object which takes a StringWriter as a parameter). The first parameter is an IHtmlHelper<TModel>, used to attach this method to the HtmlHelper static class as an extension method. After that, we create, using HtmlHelper, all the elements we want to generate (in the current case, a label, a textbox, and a validation message for one model property). We add these elements as a generated string, attached to an HTML encoding format to the StringWriter we return.

Get ASP.NET Core MVC 2.0 Cookbook 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.