Named Tag Helpers? #3233
Comments
@RehanSaeed I suggest creating a If you need to split things between two tag helpers, use |
@dougbu I believe the scenario here is that he needs to add the |
I was not aware of the
I don't actually need any properties on |
Looks like it should work with one caveat: The Likely easiest to use Separately,
It's fine to define a tag helper without properties. |
So in conclusion:
Presumably the tag helper is automatically added. But what If I don't use the |
The code will execute but the I misspoke earlier. The |
I can't seem to find any examples in the ASP.NET source using
I am still going to experiment with adding a dummy required property. This would force users to opt-in to using the tag helper, rather than it running automatically just because they added the tag helper DLL. It would be nice if value-less attributes could be added to tag helpers to facilitate this feature for bool properties:
|
@RehanSaeed are you running into any issues with this approach? If not it's probably time to close this issue. |
@dougbu I've finally managed to find time to test this out and it doesn't seem to work. The I can find no examples of how to use the Items dictionary, do you know of any? |
Is the |
Yes but using a Index.cshtml
_Layout.cshtml
|
@RehanSaeed individual You have at least three options with the current framework:
[HtmlAttributeNotBound]
[ViewContext]
public ViewContext ViewContext { get; set; }
...
ViewContext.ViewData[nameof(OpenGraphPrefixTagHelper))] = ...;
|
Filed aspnet/Razor#564 about the potential design point. I don't expect changes in this area before v1 of MVC 6 hits RTM. |
Thanks @dougbu. I think option two is the simplest workaround so that's the approach I'll go with. Can that ViewContext property be made internal? My TagHelper doubles as a HTML helper so it would be useful to cut out the noise. |
No, tag helper activation ignores properties that are When used as an HTML helper, how does your class get the current |
Ok, no problem. No need to use ViewContext. The ViewBag is available in the view itself, so you can do something like this:
|
I have built two-dozen HTML helpers I am converting to tag helpers for ASP.NET 5 MVC 6 to generate Facebook Open Graph meta tags. Here is an example of the 'website' type:
Index.cshtml
Each Open Graph object type has a special namespace which has to be added to the head tag e.g.
_Layout.cshtml
I managed to do this using HTML Helpers in the past by using the ViewBag and the
Namespace
getter property on theOpenGraphWebsite
class like so:Index.cshtml
_Layout.cshtml
Is there a way to achieve a similar result with tag helpers? Some way of naming a tag helper or referring to it?
The text was updated successfully, but these errors were encountered: