dotnet/aspnetcore

ASP.NET Core add Tag Helpers to replace HTML Helpers such as @Html.DisplayFor

Open

#3,956 opened on Nov 7, 2018

View on GitHub
 (10 comments) (6 reactions) (0 assignees)C# (10,653 forks)batch import
area-mvcenhancementfeature-mvc-razor-viewsgood first issue

Repository metrics

Stars
 (37,933 stars)
PR merge metrics
 (Avg merge 16d 9h) (258 merged PRs in 30d)

Description

Feature request In all our on-boarding tutorials (MVC and Razor Pages), new programmers are introduced to both Tag Helpers and HTML Helpers. HTML Helpers are especially complicated. See the Index.cshtml Razor Page

What follows is the complicated explanation of the lambda expression used in the HTML Helper:


Examine the lambda expression used in the following HTML Helper: @Html.DisplayNameFor(model => model.Movie[0].Title))

The DisplayNameFor HTML Helper inspects the Title property referenced in the lambda expression to determine the display name. The lambda expression is inspected rather than evaluated. That means there is no access violation when model, model.Movie, or model.Movie[0] are null or empty. When the lambda expression is evaluated (for example, with @Html.DisplayFor(modelItem => item.Title)), the model's property values are evaluated.


I was forced to add the lambda explanation because of so many customer questions.

The very next section on the Create Razor Page is all Tag Helpers.

I recommend adding Tag Helpers (TH) to replace all the HTML Helpers that are scaffolded. The scaffolder will need to use the new TH's. This will significantly lower the barrier to entry. New developers can focus on THs and not be forced to learn HTML Helpers simultaneously.

cc @DamianEdwards

The intro tutorials generate a lot of issues because of the complexity of HTML Helpers. For example, Confusing example of DisplayFor

Contributor guide