Open Closed

Pages generated with Abp Suite don't pass filters when requesting Excel file #6194


User avatar
0
roberto.fiocchi created
  • ABP Framework version: v7.4.2
  • UI Type: Blazor WASM
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): no
  • Exception message and full stack trace: none
  • Steps to reproduce the issue:
    • Create a new solution using Abp Suite.
    • Create a new Entity called "Book" using Abp Suite and generate the code.
    • Notice how the filters are present in the BookExcelDownloadDto, but in the razor page's code only the FilterText filter has been passed:

BookExcelDownloadDto.cs:

public class BookExcelDownloadDto
{
    public string DownloadToken { get; set; } = null!;

    public string? FilterText { get; set; }

    public string? Title { get; set; }
    public DateTime? PublishDateMin { get; set; }
    public DateTime? PublishDateMax { get; set; }
    public bool? InInventory { get; set; }

    public BookExcelDownloadDto()
    {

    }
}

Books.razor.cs:

public partial class Books
{
	// OTHER PAGE CODE HERE
	private  async Task DownloadAsExcelAsync()
	{
		var token = (await BooksAppService.GetDownloadTokenAsync()).Token;
		var remoteService = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultOrNullAsync("ExcelTest") ??
		await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultOrNullAsync("Default");
		NavigationManager.NavigateTo($"{remoteService?.BaseUrl.EnsureEndsWith('/') ?? string.Empty}api/app/books/as-excel-file?DownloadToken={token}&FilterText={Filter.FilterText}", forceLoad: true);
	}
	// OTHER PAGE CODE HERE
}

5 Answer(s)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hello roberto.fiocchi@mcsi.it ,

    The issue you're encountering is that the FilterText property is the only one being passed to the URL when generating the Excel download link. This is because the DownloadAsExcelAsync method only explicitly passes the FilterText property. To include the other filter properties, you'll need to modify the method to explicitly pass them as well.

    Thanks,

  • User Avatar
    0
    roberto.fiocchi created

    Hello roberto.fiocchi@mcsi.it ,

    The issue you're encountering is that the FilterText property is the only one being passed to the URL when generating the Excel download link. This is because the DownloadAsExcelAsync method only explicitly passes the FilterText property. To include the other filter properties, you'll need to modify the method to explicitly pass them as well.

    Thanks,

    Hi, I think there might have been a misunderstanding, i was reporting a bug since it should be Abp Suite's job to add those filters when the code is generated like it does with the Page Filters. If i have an entity that has a lot of filters it would take me a while to add all of them manually, time that can be saved if automated with Abp Suite.

    Also, is it not wiser to use a POST request rather then a GET because the query parameters in a GET requests has a 2048 character limit and could possibly go over if i have enough filters?

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi, yes you are right the other filters should also be passed to the parameter and the filtering should work for them as well. I have created an internal issue (#15729) for this and will fix it asap.

    Also, is it not wiser to use a POST request rather then a GET because the query parameters in a GET requests has a 2048 character limit and could possibly go over if i have enough filters?

    I understand your intent but since we are getting a result back and not adding or updating any record to a datastore, and instead just collecting the result and returning it GET request seems more proper, according to REST API guides.

  • User Avatar
    0
    roberto.fiocchi created

    Hi, yes you are right the other filters should also be passed to the parameter and the filtering should work for them as well. I have created an internal issue (#15729) for this and will fix it asap.

    Also, is it not wiser to use a POST request rather then a GET because the query parameters in a GET requests has a 2048 character limit and could possibly go over if i have enough filters?

    I understand your intent but since we are getting a result back and not adding or updating any record to a datastore, and instead just collecting the result and returning it GET request seems more proper, according to REST API guides.

    Hi, Thanks so much for the help and understanding! We'll wait for the fix.

    P.S: We don't know if its intended but we also noticed that with ABP 7.4.2 under HttpApi project a "TestModel.cs" is created when initializing the project with Abp Suite

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    P.S: We don't know if its intended but we also noticed that with ABP 7.4.2 under HttpApi project a "TestModel.cs" is created when initializing the project with Abp Suite

    Thanks for noting this, I have taken note of this one too.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38