Enclose a list of tags (taghelper) by a parent tag

做~自己de王妃 提交于 2019-12-11 14:49:56

问题


I need to achieve like below

<MyTagList>
    <MyTag></MyTag>
    <MyTag></MyTag>
</MyTagList>

When ever I use MyTag in design time, it need to be enclosed automaticaly by MyTagList or MyTag should error that it must be enclosed by MyTagList


回答1:


You can't do this today at design time. You can however do it partially at runtime by utilizing TagHelperContext.Items. By using the Items property you can ensure that each tag is enclosed by a parent tag and throw if it's not. Insert an indicator into the Items bag in your parent element and verify that it exists in child elements.

As for supporting this in the future there are two issues open to add design time support:

  • https://github.com/aspnet/Razor/issues/255
  • https://github.com/aspnet/Razor/issues/474

Hope this helps!



来源:https://stackoverflow.com/questions/31790549/enclose-a-list-of-tags-taghelper-by-a-parent-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!