Unable to Export Grid Data to Excel or CSV from a Page with a Blazor Data Grid driven by 2 Data Pickers

I have created a Razor Page and accompanying Code Behind which Displays a Blazor Data Grid driven by 2 Blazor Data Pickers. All the events fire correctly such that the Grid Data displays the desired data within the 2 separate Data Picker Values inclusive. My problem is that when I execute the ExportClick functionality which is modeled after all the others with my addition of the values for each of the Data Pickers, the function fails and I get a Page not Found error. All the functions are defined correctly in my DbContext, DbService, and in my code behind. However, it just does not work.

    protected override async Task OnInitializedAsync()
    {
        DateTime d = DateTime.Today.Date;
        reportStartDate = new DateTime(d.Year, d.Month  - 1, 1);
        reportEndDate = d.Date;
        retrieveAccountTransactionsByDateRanges = await ApexDbService.GetRetrieveAccountTransactionsByDateRanges(reportStartDate.ToString(), reportEndDate.ToString(), new Query { Filter = $@"i => i.DateEntered.Contains(@0) || i.Source.Contains(@0) || i.Description.Contains(@0) || i.Reference.Contains(@0) || i.Tax.Contains(@0) || i.CurrencyCode.Contains(@0) || i.AccountClass.Contains(@0) || i.AccountType.Contains(@0)", FilterParameters = new object[] { search } });
     }

     protected DateTime? reportStartDate;

     protected DateTime? reportEndDate;

    protected async Task ExportClick(RadzenSplitButtonItem args)
    {
        if (args?.Value == "csv")
        {              
            await ApexDbService.ExportRetrieveAccountTransactionsByDateRangesToCSV(reportStartDate.ToString(), reportEndDate.ToString(), new Query
            { 
                Filter = $@"{(string.IsNullOrEmpty(grid0.Query.Filter)? "true" : grid0.Query.Filter)}", 
                OrderBy = $"{grid0.Query.OrderBy}", 
                Expand = "", 
                Select = string.Join(",", grid0.ColumnsCollection.Where(c => c.GetVisible()).Select(c => c.Property))
            }, "RetrieveAccountTransactionsByDateRanges");
        }

        if (args == null || args.Value == "xlsx")
        {
            await ApexDbService.ExportRetrieveAccountTransactionsByDateRangesToExcel(reportStartDate.ToString(), reportEndDate.ToString(), new Query
            { 
                Filter = $@"{(string.IsNullOrEmpty(grid0.Query.Filter)? "true" : grid0.Query.Filter)}", 
                OrderBy = $"{grid0.Query.OrderBy}", 
                Expand = "", 
                Select = string.Join(",", grid0.ColumnsCollection.Where(c => c.GetVisible()).Select(c => c.Property))
            }, "RetrieveAccountTransactionsByDateRanges");
        }
    }

Would it be possible for you to see an error as I have been looking at this for many hours? I am sure that it should be a simple error but I just can't find it, ugh.

Check if you have the export controllers which actually handles the export:

After Adding a lot of Column Definitions which Radzen Blazor Studio missed in the DB Context (such as Column Types, Precision, and Scale), I can state for certain that the Export Function is contained within my ExportApexDbController as you mentioned.

It is listed as

    [HttpGet("/export/ApexDb/retrieveaccounttransactionsbydateranges/csv(dateFrom='{dateFrom}', dateTo='{dateTo}')")]
    [HttpGet("/export/ApexDb/retrieveaccounttransactionsbydateranges/csv(dateFrom='{dateFrom}', dateTo='{dateTo}', fileName='{fileName}')")]
    public async Task<FileStreamResult> ExportRetrieveAccountTransactionsByDateRangesToCSV(string dateFrom, string dateTo, string fileName = null)
    {
        return ToCSV(ApplyQuery(await service.GetRetrieveAccountTransactionsByDateRanges(dateFrom, dateTo), Request.Query), fileName);
    }

    [HttpGet("/export/ApexDb/retrieveaccounttransactionsbydateranges/excel(dateFrom='{dateFrom}', dateTo='{dateTo}')")]
    [HttpGet("/export/ApexDb/retrieveaccounttransactionsbydateranges/excel(dateFrom='{dateFrom}', dateTo='{dateTo}', fileName='{fileName}')")]
    public async Task<FileStreamResult> ExportRetrieveAccountTransactionsByDateRangesToExcel(string dateFrom, string dateTo, string fileName = null)
    {
        return ToExcel(ApplyQuery(await service.GetRetrieveAccountTransactionsByDateRanges(dateFrom, dateTo), Request.Query), fileName);
    }

Which Razor Blazor Studio Scaffolded for the Apex Db Connection.

Also, while running the Radzen Blazor Studio IDE in the Debug Mode (thank you so much for the feature!!!), and having active breakpoints on the To Excel and To CSV functions in the page, I see the following:

info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (1ms) [Parameters=[p0='?' (Size = 4000), p1='?' (Size = 4000)], CommandType='Text', CommandTimeout='30']
EXEC [dbo].[RetrieveAccountTransactionsByDateRange] @dateFrom=@p0, @dateTo=@p1

This is curious as it seems to mean that neither of the Date values which I sent were used at all.

  public async Task ExportRetrieveAccountTransactionsByDateRangesToExcel(string dateFrom, string dateTo, Query query = null, string fileName = null)
  {
      navigationManager.NavigateTo(query != null ? query.ToUrl($"export/apexdb/retrieveaccounttransactionsbydateranges/excel(dateFrom='{dateFrom}', dateTo='{dateTo}', fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')") : $"export/apexdb/retrieveaccounttransactionsbydateranges/excel(dateFrom='{dateFrom}', dateTo='{dateTo}', fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')", true);
  }

  public async Task ExportRetrieveAccountTransactionsByDateRangesToCSV(string dateFrom, string dateTo, Query query = null, string fileName = null)
  {
      navigationManager.NavigateTo(query != null ? query.ToUrl($"export/apexdb/retrieveaccounttransactionsbydateranges/csv(dateFrom='{dateFrom}', dateTo='{dateTo}', fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')") : $"export/apexdb/retrieveaccounttransactionsbydateranges/csv(dateFrom='{dateFrom}', dateTo='{dateTo}', fileName='{(!string.IsNullOrEmpty(fileName) ? UrlEncoder.Default.Encode(fileName) : "Export")}')", true);
  }

This what the function assembled but I get a page not found error:
https://localhost:5001/export/apexdb/retrieveaccounttransactionsbydateranges/excel(dateFrom='2/1/2023%2012:00:00%20AM',%20dateTo='3/15/2023%2012:00:00%20AM',%20fileName='RetrieveAccountTransactionsByDateRanges')?$filter=true&$select=DateEntered,Source,Description,Reference,DebitAmount,CreditAmount,RunningBalance,CurrencyCode,AccountCode,AccountClass,AccountType,CustomerId,OrderId. The only weirdness that I can see is the fact that time is included and I didn’t send any.

Any assistance would be appreciated. Thank you.

Hi @FastTrak,

To comment on this issue we will need application where we can reproduce this. You can send such at info@radzen.com, if the zip is too big you can use Google Drive or similar.