-
Notifications
You must be signed in to change notification settings - Fork 11.7k
ASP.NET Core add Tag Helpers to replace HTML Helpers such as @Html.DisplayFor #3956
Copy link
Copy link
Open
Open
Copy link
Labels
area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis 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 viewsFeatures related to the Razor view engine for Razor pages and MVC viewsgood first issueGood for newcomers.Good for newcomers.
Milestone
Description
Activity
Metadata
Metadata
Assignees
Labels
area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis 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 viewsFeatures related to the Razor view engine for Razor pages and MVC viewsgood first issueGood for newcomers.Good for newcomers.
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
DisplayNameForHTML Helper inspects theTitleproperty 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 whenmodel,model.Movie, ormodel.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