Since the release of ASP.Net Core, Asp team is pushing the use of TagHelpers more than the HTML helpers.
While scaffolding view from controller, ASP.Net Core creates add, edit page with the use of TagHelpers, But if you notice the index page they use old HTML helpers.
//Ex:
<th>
@Html.DisplayNameFor(model => model.Package)
</th>
It is very confusing to understand what the ASP.net Core Teams agenda. Does anybody know which is correct way of doing this in ASP.net Core? My guess is that @Html.DisplayNameFor(model => model.Package)
will be marked as deprecated soon. Please explain?
Not every Html helper has an equivalent Tag helper. For instance, there is no equivalent Tag helper for @Html.DisplayNameFor(m => m.Property)
or @Html.EditorForModel()
. It makes sense because @Html.DisplayNameFor(m => m.Property)
and @Html.EditorForModel()
doesn't really output an HTML tag.
So use Tag helpers in favor of Html helpers if there is an equivalent. Otherwise, use Html helpers.
I don't think @Html.DisplayNameFor(m => m.Property)
will be marked as deprecated (nor will any other display templates or editor templates such as @Html.EditorForModel()
). These will continue to be used in ASP.NET Core.
Also, you might be interested in this thread regarding a TagHelper equivalent to Html.DisplayNameFor: https://github.com/aspnet/Mvc/issues/2387
According to that thread,
https://github.com/aspnet/Mvc/issues/3003
it seems like for the moment DisplayNameFor is here to stay and that there is no Tag Helper for your solution.
They mention <label asp-for="blabla"></label>
a lot but this is not the same.
I think tag helpers is the way to go, it is more readable, cleaner and can be used to create more complex tags that simulate the user controls in web forms days
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With