dotnet / dotnet/aspnetcore

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

Open
#3,956 10 comments 6 reactions 0 assignees View on GitHub
area-mvc enhancement feature-mvc-razor-views good first issue
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

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](https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/page#index)

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](https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/page?view=aspnetcore-2.1#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](https://github.com/dotnet/AspNetCore.Docs/issues/22000)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.