问题
Can I use ViewComponents in a page like this.
<vc:parent-component>
<some random html>
</parent-component>
when I try this it renders out only parent component. In cshtml of parent-component I am looking for something like below
<h2>Parent component markup</h2>
@RenderChildren()??
<h2>Parent component markup end</h2>
So result will be
<h2>Parent component markup</h2>
@RenderChildren()
<h2>Parent component markup end</h2>
回答1:
You cannot use random html inside ViewComponent
tag helper as you did. May be your are considering ViewComponent
tag helper as like as html element. Actually its not html element, rather its a razor code.
According to the Invoking a view component as a Tag Helper documentation, Your ViewComponent
tag helper should be like as follows
<vc:[view-component-name]
parameter1="parameter1 value"
parameter2="parameter2 value">
</vc:[view-component-name]>
来源:https://stackoverflow.com/questions/55206787/viewcomponents-with-children