Getting all of the children Tag Helpers in a parent Tag Helper Asp.Net Core

Viewed 1588

I am trying to write two Tag helpers that are used to localize strings in razor views. The purpose of the parent tag is to gather all of the keys that are requested by the child tags and get them from the database in one batch and cache them.

Then the child tags will use the cached versions, this way I am hoping to lower the load on the database. I am looking for something like this:

<parent-tag>
   <child-tag key="Hello" /> 
     some HTML here
   <child-tag key="Hi!" /> 
</parent-tag>

I want to be able to get a list of objects in the Parent tag's Invoke method.

I have also tried storing data in TagHelperContext to communicate with other tag helpers, but this will not work either, because I have to call output.GetChildContentAsync() inside the Parent's Invoke method, which defeats the whole purpose of the caching.

1 Answers
Related