ASP.NET 5 TagHelper Complex

Is it possible to build a complex taghelper in ASP.NET 5 where the custom tag has children / tags of a specific type?

<blockSection columns="2" labelPosition="left">
   <inputField for="name" />
   <inputField for="email" required="true"/>
</blockSection>

      

In the above example, blockSection will be a TagHelper that only accepts inputField tags.

+3


source to share


1 answer


Without a whole lot of confusion (disassembling body tags or creating TagHelper

that targets everything), you can't do it 100% today (beta6).

You can partially fix your problem by making sure that the elements <inputField>

only show up inside the tag <blockSection>

(it wouldn't hurt you to put things like <p>

inside <blockSection>

). Can be achieved by using a package context.Items

to notify InputFieldTagHelper

that it is (or not) encapsulated <blockSection>

. See this issue for information on how to establish a relationship between child => parent.



If you're willing to wait for this Razor issue ; you will be able to apply tags that may appear inside your TagHelper

.

Another similar SO issue for reference.

+3


source







All Articles