I'm currently trying to abstract away a mechanism to enumerate an IAsyncEnumerable as it becomes available.
I have a base component class that looks roughly like this
// EnumerableRazorComponentBase.razor
@typeparam TObject
@if (!(this.enumerationTask?.IsCompleted ?? false))
{
// Display loading bar
}
// EnumerableRazorComponentBase.razor.cs
public abstract partial class EnumerableRazorComponentBase<TObject> : ComponentBase
{
private Task enumerationTask;
// rest of enumeration logic...
}
Now I inherit this base class in a razor component
// SomeComponent.razor
@inherits EnumerableRazorComponentBase<IMyInterface>
// other razor markup
@code {
// rest impl
}
EnumerableRazorComponentBase.razor.cs
is inherited properly and works as expected, but the markup in EnumerableRazorComponentBase.razor
is not added to the markup of SomeComponent.razor
.
Is it possible to inherit razor markup from a base class, and if so what am I doing wrong/what am I missing?
Yes it's possible. Just add a call to base.BuildRenderTree like so:
// SomeComponent.razor
@inherits EnumerableRazorComponentBase<IMyInterface>
@{
base.BuildRenderTree(__builder);
}
<h2>Additional markup in subclassed component</h2>
@code {
// rest impl
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With