You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ASP.NET Core add Tag Helpers to replace HTML Helpers such as @Html.DisplayFor #3956
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.
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.
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.
There are still no plans to put this in the product that I know of (@danroth27 for comment) but you could use the TagHelperPack package to get this functionality today.
@DamianEdwards@danroth27 HTML helpers are one of the biggest hurdles to onboarding ASP.NET Core UI. The scaffolding engine generates a mix of HTML Helpers and Tag Helpers (TH). Any chance we could eventually get TH replacements so there's only one new thing to learn? V7? V8? Please review my original complaint on complexity of HTML Helpers magic.
Reopening this and moving to the Backlog. While we don't plan to work on this at the moment, we will accept community contributions here in case someone is interested to send us a PR.
Please note that my Tag Helpers use reflection to call the appropriate methods on HtmlHelper as the current code in MVC isn't factored such that it can be done through public APIs. If this were done first-class in MVC itself it would hopefully be much more straightforward.
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.
Activity
mkArtakMSFT commentedon Nov 7, 2018
Thanks for contacting us, @Rick-Anderson.
We have no plans to invest in this area in the near future.
vanhoutenbos commentedon Nov 5, 2019
Any plans for this (1 year later) I am running into this issue constantly and have not found a proper solution yet.
DamianEdwards commentedon Nov 5, 2019
There are still no plans to put this in the product that I know of (@danroth27 for comment) but you could use the TagHelperPack package to get this functionality today.
vanhoutenbos commentedon Nov 5, 2019
Thank you for sharing that package, I will look into that!
Rick-Anderson commentedon Feb 19, 2021
@DamianEdwards @danroth27 HTML helpers are one of the biggest hurdles to onboarding ASP.NET Core UI. The scaffolding engine generates a mix of HTML Helpers and Tag Helpers (TH). Any chance we could eventually get TH replacements so there's only one new thing to learn? V7? V8? Please review my original complaint on complexity of HTML Helpers magic.
TagHelperPack package doesn't help the tutorials.
@mkArtakMSFT fine to keep closed but can you allow customers to chime in?
mkArtakMSFT commentedon Mar 9, 2021
Reopening this and moving to the
Backlog. While we don't plan to work on this at the moment, we will accept community contributions here in case someone is interested to send us a PR.Rick-Anderson commentedon Mar 9, 2021
See https://github.com/DamianEdwards/TagHelperPack
DamianEdwards commentedon Mar 9, 2021
Please note that my Tag Helpers use reflection to call the appropriate methods on
HtmlHelperas the current code in MVC isn't factored such that it can be done through public APIs. If this were done first-class in MVC itself it would hopefully be much more straightforward.pranavkm commentedon Mar 10, 2021
Thanks @DamianEdwards, that's a good starting point to use as a template. In this particular implementation, we would
GenerateDisplayNametoIHtmlGenerator, possibly as a default interface method.HtmlHelper.GenerateDisplayNameto this interface method.GenerateDisplayandGenerateEditor.9 remaining items
Rick-Anderson commentedon Apr 10, 2025
Closing this as stale. @guardrex will correct me if I'm wrong.