diff --git a/src/Masa.Blazor/Components/PermissionView/PermissionView.cs b/src/Masa.Blazor/Components/PermissionView/PermissionView.cs index 85c91b1d12..0f7b341710 100644 --- a/src/Masa.Blazor/Components/PermissionView/PermissionView.cs +++ b/src/Masa.Blazor/Components/PermissionView/PermissionView.cs @@ -14,6 +14,9 @@ public class PermissionView : ComponentBase [Parameter] public RenderFragment? ChildContent { get; set; } + [Parameter] + public RenderFragment? FallbackContent { get; set; } + [Parameter, EditorRequired] public string Code { get; set; } = null!; @@ -37,13 +40,11 @@ protected override async Task OnInitializedAsync() protected override void BuildRenderTree(RenderTreeBuilder builder) { - if (User == null || Validator == null) + if (User == null || Validator == null || !Validator.Validate(Code, User)) { - return; + builder.AddContent(0, FallbackContent); } - - var valid = Validator.Validate(Code, User); - if (valid) + else { builder.AddContent(0, ChildContent); }