From cb431a15aa95ef1992a58d7b85259bece09bc5cb Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 21 Oct 2026 20:59:03 +0800 Subject: [PATCH] Go back to the previous page when the last item of a MudBlazor CRUD page is deleted --- .../src/Volo.Abp.MudBlazorUI/AbpMudCrudPageBase.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.MudBlazorUI/AbpMudCrudPageBase.cs b/framework/src/Volo.Abp.MudBlazorUI/AbpMudCrudPageBase.cs index 9bc201bdca..c702a94318 100644 --- a/framework/src/Volo.Abp.MudBlazorUI/AbpMudCrudPageBase.cs +++ b/framework/src/Volo.Abp.MudBlazorUI/AbpMudCrudPageBase.cs @@ -180,6 +180,7 @@ public abstract class AbpMudCrudPageBase< protected virtual int PageSize { get; set; } = LimitedResultRequestDto.DefaultMaxResultCount; + protected IReadOnlyList Entities = Array.Empty(); protected int CurrentPage = 1; protected string CurrentSorting = default!; protected TGetListInput GetListInput = new TGetListInput(); @@ -349,6 +350,7 @@ public abstract class AbpMudCrudPageBase< await UpdateGetListInputAsync(); var result = await AppService.GetListAsync(GetListInput); var items = MapToListViewModel(result.Items); + Entities = items; await InvokeAsync(StateHasChanged); @@ -599,7 +601,13 @@ public abstract class AbpMudCrudPageBase< protected virtual async Task OnDeletedEntityAsync() { - if (_dataGrid != null) + if (Entities.Count == 1 && CurrentPage > 1) + { + // The data grid loads the previous page when it receives the new CurrentPage + CurrentPage -= 1; + await InvokeAsync(StateHasChanged); + } + else if (_dataGrid != null) { await InvokeAsync(() => _dataGrid.ReloadServerDataAsync()); }