Say I have a component MyComponent that prints out this HTML:
<my-component attr1="@(Attr1)"
attr2="@(Attr2)"
@attributes="@(AdditionalAttributes)">
@(ChildContent)
</my-component>
Now I want to have MoreDetailedComponent that inherits MyComponent and declares Attr3. Can I reuse the above code somehow so I do not have to rewrite it (in reality there are tens of them):
@inherits MyComponent
<my-component attr1="@(Attr1)"
attr2="@(Attr2)"
attr3="@(Attr3)"
@attributes="@(AdditionalAttributes)">
@(ChildContent)
</my-component>
Turn out it's very simple, I just extend the
AdditionalAttributeslike this:MyComponentshould prints it out like this:MoreDetailedComponentdoes not need its own Razor file but instead just overrideProtectedAdditionalAttributes: