Skip to content

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

Open
@Rick-Anderson

Description

@Rick-Anderson

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-mvc-razor-viewsFeatures related to the Razor view engine for Razor pages and MVC viewsgood first issueGood for newcomers.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions