[CLOSED] Download File via DirectEvent

  1. #1

    [CLOSED] Download File via DirectEvent

    How would a file download that is initiated via a DirectEvent work in Ext.NET v7?

    This forum post explains how it worked in a previous version. I can't find any 'IsUpload' property for a click event handler in v7 though. I assume things have changed somewhat in the framework since that post was written.

    In the code-behind of a Razor page, I want to create a button that, when clicked, will invoke a Direct Event for the page. Something like this:

                    new Button
                    {
                        Text = "Export",
                        DirectEvents =
                        {
                            new ClickDirectEventHandler
                            {
                                Url = "ExportToExcel", // How to set page handler instead?                           
                                ExtraParams =
                                {
                                    new DirectEventParameter
                                    {
                                        Key = "TabName",
                                        Value = tabName
                                    }
                                }
                            }
                        }
                    }
    The handler for the Direct Event looks something like this:

            [Direct]
            public async Task<IActionResult> OnPostExportToExcelAsync([FromBody] ExcelExportData request)
            {
                byte[] fileContents = DoWorkToCreateExcelFile();
    
                return File(
                    fileContents,
                    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                    "MyFile.xslx");
            }
    Thanks

    Paul
  2. #2
    Hello Paul!

    You probably want to check this forum thread: Download File using DirectEvent

    We answered that very similar question some time ago and we still didn't receive a feedback from the one asking it, so it'd be appreciated if you can let us know if that helps or not, so we could improve the answer.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Fabricio

    Yes, it did help. I ended up attaching a JavaScript listener to the button click event, and using the listener to trigger the submission of a HTML form element on the page that invoked the file download action of my Razor page. This worked OK, so no need to use a DirectEvent.

    Regards

    Paul
  4. #4
    Thanks for the feedback, Paul, glad it helped you find the best approach to solve the file download functionality!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Download File using DirectEvent (MVC)
    By dnakorea in forum 7.x Classic Help
    Replies: 2
    Last Post: Mar 26, 2021, 1:31 AM
  2. Download File using DirectEvent
    By bbros in forum 7.x Classic Premium Help
    Replies: 1
    Last Post: Mar 10, 2021, 9:21 PM
  3. Download File using DirectEvent
    By Daniil in forum Examples and Extras
    Replies: 0
    Last Post: Dec 13, 2013, 4:02 AM
  4. [CLOSED] MVC DirectEvent Download File
    By MWM2Dev in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: May 17, 2013, 11:49 AM
  5. [CLOSED] [1.0] - MVC - DirectEvent Download File
    By drkoh in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 23, 2010, 8:26 PM

Posting Permissions