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

2019-08-14 04:00发布

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条回答
Evening l夕情丶
2楼-- · 2019-08-14 04:05

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:

Hope this helps!

查看更多
登录 后发表回答