rwkiii
rwkiii

Reputation: 5846

Submit HTTP form a second time without cancelling the first Submit

I am calling an MVC ActionResult to generate a .ZIP of reports. This ActionResult is decorated with [HttpPost] and returns a FilePathResult.Controller.File object to the client.

On its own, the .ZIP implementation works perfectly, but I now have a need to send a second, independent file that cannot be included in the first .ZIP.

The .ZIP file is always downloaded by the client browser. The second file, a PDF, is downloaded conditionally.

Independently, my coding works great, but they will not work together since my second HTTP POST appears to be cancelling the first one.

The jQuery:

$('#btnDownloadReports li a').click(function (event) {

    event.preventDefault;

    $(this).parents("form")
        .attr("method", "POST")
        .attr("action", "/MyController/MyOutputZIP/?selectionId=" + $('#SelectionId').val())
        .submit();

    if ($(this).data('reporttype') == 'pdf') {
        $(this).parents("form")
            .attr("method", "POST")
            .attr("action", "/MyController/MyOutputPDF/?selectionId=" + $('#SelectionId').val())
            .submit();
    }

    return false;
}

I see a SO post that might provide a hint, but I'm not sure how to apply it in my case.

Can anyone point me on how to make the second HTTP POST trigger after the first HTTP POST is completed?

Upvotes: 0

Views: 38

Answers (2)

NicoJuicy
NicoJuicy

Reputation: 3528

I did something similar some time ago. My solution was to open a new window with javascript for downloading an additional file.

The enduser has to "approve" the website for opening new windows though, this should only be once...

Upvotes: 0

Blindy
Blindy

Reputation: 67487

Instead of what is essentially a hack, why not move the logic on the server side and let it decide how many and which files to send you? Consider that anything on the client side can be maliciously changed.

Once on the server side you have two different options:

  • multi-part documents, and simply return the two files in the same stream.
  • go old-school and simply zip your documents together if needed (otherwise return just the one document unzipped).

Upvotes: 2

Related Questions