diff --git a/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Components/LayoutHooks/LayoutHook.razor.cs b/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Components/LayoutHooks/LayoutHook.razor.cs index 18fbcd89c2..729b990f34 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Components/LayoutHooks/LayoutHook.razor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/Components/LayoutHooks/LayoutHook.razor.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; @@ -26,6 +25,7 @@ public partial class LayoutHook : ComponentBase if (LayoutHookOptions.Value.Hooks.TryGetValue(Name, out var layoutHooks)) { layoutHooks = layoutHooks + .Where(IsComponentBase) .WhereIf(string.IsNullOrWhiteSpace(Layout), x => x.Layout == Layout) .ToList(); } @@ -36,4 +36,9 @@ public partial class LayoutHook : ComponentBase return Task.CompletedTask; } + + protected virtual bool IsComponentBase(LayoutHookInfo layoutHook) + { + return typeof(ComponentBase).IsAssignableFrom(layoutHook.ComponentType); + } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Components/LayoutHook/LayoutHookViewComponent.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Components/LayoutHook/LayoutHookViewComponent.cs index 5bd18e4c31..553c7908c4 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Components/LayoutHook/LayoutHookViewComponent.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Components/LayoutHook/LayoutHookViewComponent.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Volo.Abp.Ui.LayoutHooks; @@ -17,11 +18,17 @@ public class LayoutHookViewComponent : AbpViewComponent public virtual IViewComponentResult Invoke(string name, string layout) { - var hooks = Options.Hooks.GetOrDefault(name)?.ToArray() ?? Array.Empty(); - + var hooks = Options.Hooks.GetOrDefault(name)?.Where(IsViewComponent).ToArray() + ?? Array.Empty(); + return View( "~/Volo/Abp/AspNetCore/Mvc/UI/Components/LayoutHook/Default.cshtml", new LayoutHookViewModel(hooks, layout) ); } + + protected virtual bool IsViewComponent(LayoutHookInfo layoutHook) + { + return typeof(ViewComponent).IsAssignableFrom(layoutHook.ComponentType); + } }