0

I have a button which when I click, I want to export several CSV files together. But I am not sure how to do that. (I have 'Function1' and 'Function2', when the button is clicked, I want both functions to be called and each of them generates a CSV file)

I have some javascript code to call the functions in the controller:

$('#exportReport').click(function () {
            var originalAction = document.forms[0].action;
            if (originalAction.indexOf("CorporateProfile") !== -1) {
                document.forms[0].action = "/web/admin/configurationreports/Function1";

                //document.forms[1].action = "/web/admin/configurationreports/Function2";
                document.forms[0].submit();
                document.forms[0].action = originalAction;    
            }                
            return false;
        });

so when the 'exportReport' button is clicked, I want to call both 'Function1' and 'Function2' in the controller

Below is how the 'Function1' look like:

    [HttpPost]
    public ActionResult Function1(ConfigurationReportsCorporateProfileViewModel viewModel)
    {
       //inside this I generate a CSV file
        var bytes = encoding.GetBytes(stringBuilder.ToString());
        return File(bytes, "text/csv", "function1.csv");
    }

And I want to call 'Function2' as well but I am not sure how to do that. (would it be something like add to the javascript document.forms.action?)

CRABOLO
  • 8,605
  • 39
  • 41
  • 68
user1642888
  • 127
  • 1
  • 1
  • 8

2 Answers2

1

You need to zip the files or make 2 requests. See already answered: https://stackoverflow.com/a/1060576/532772

Community
  • 1
  • 1
ejohansson
  • 2,832
  • 1
  • 23
  • 30
0

Not sure if you can return multiple files. However, what I do is to create a zip on the fly, add both CSV files to it and return the zip file instead. It is real easy. You may use ICSharpCode.SharpZipLib.Zip API.

Allen King
  • 2,372
  • 4
  • 34
  • 52