Closed tomlm closed 1 year ago
Thanks! I plan to work on this a bit more and turn it into a nuget package with a companion VS Extension for avoiding boilerplate. The main thing I wanted to solve that I didn't find originally was how to not force the user to have to inject the IHtmlHelper and instead just have the dependency as part of the base class, which your sample covers and it's gonna be a huge improvement on this final product.
Ideally, I don't think something like this should be an 3rd party package, but something that the framework supports out of the box. But I understand the focus (and money) right now is in Blazor, not in adding better composition techniques inside plain old MVC. Though I would say that there are still use cases for a classic MVC approach in applications where you need to get going quickly and a rich web UI doesn't matter as much.
I do plan to add a feature request into the ASP.NET Core repo when I have finished this properly and leave this repo as a sample should this feature ever become part of the framework itself. Ideally this could be useful by allowing ways of using named slots into it (like Svelte).
But once again, thanks for the feedback, I never thought this would get any attention before me posting the related blog post talking about it.
Published the nuget package with the changes you suggested two days ago. Closing the issue. Working on a small documentation site.
Thank you for figuring this out! I think your code can be simplified quite a bit, in fact all the way down to a single class which I call ViewTagHelper, (as I think it is a bit more aligned with the aspnetcore nomenclature.)
Here's the classs
You will see that:
A sample TagHelper then looks like this: ~/TagHelpers/Person/PersonTagHelper.cs
and template ~/TagHelpers/Person/default.cshtml
And of course can be used then in other templates: