TagHelper cached output by calling GetChildContentAsync() and Content.GetContent()

半城伤御伤魂 提交于 2019-12-06 03:31:45
S.Serpooshan

The explanation of other answer was not clear for me, so i tested it and here is the summary:

  • await output.GetChildContentAsync(); ⇒ gets the original content inside the tag which is hard coded in the Razor file. note that it will be cached at first call and never changed at subsequent calls, So it does not reflect the changes done by other TagHelpers at runtime!

  • output.Content.GetContent(); ⇒ should be used only to get content modified by some TagHelper, otherwise it returns Empty!

Usage samples:

Getting the latest content (whether initial razor or content modified by other tag helpers):

var curContent = output.IsContentModified ? output.Content : await output.GetChildContentAsync();
string strContent = curContent.GetContent();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!