1

Heres the controller

    [ApiController, Route("api/reports"), Authorize]
    public class ReportsController : Controller

with the methods

    [HttpPost, Route("download")]
    public async Task<IActionResult> Download(string[] ids)
    {
        var cd = new System.Net.Mime.ContentDisposition("attachment") { FileName = "downloads.json" };
        Response.Headers.Add("Content-Disposition", cd.ToString());
        return Ok(await CreateDocumentsOnIds(ids));
    }

    [HttpGet, Route("{id}/download")]
    public async Task<IActionResult> Download(string id)
    {
        var cd = new System.Net.Mime.ContentDisposition("attachment") { FileName = $"document_{id}.json" };
        Response.Headers.Add("Content-Disposition", cd.ToString());
        return Ok(await CreateDocumentOnId(id));
    }

Which works fine for one Id:

    <table class="table is-fullwidth">
        <thead>
            <tr>
                <th>Link</th>
                <th>Dato</th>
            </tr>
        </thead>
        <tbody>
           @foreach (var doc in documents)
           {
              <tr>
                <td><a href="@doc.Url" target="_blank">@doc.Url</a></td>
                <td>@doc.Updated.ToShortDateString()</td>
                <td><a class="button is-link" Color=@Color.Primary href=@($"/api/reports/{doc.Id}/download")>Download</a></td>
              </tr>
           }
       </tbody>
    </table>

But I want the possibility to download several documents as one file. And in order for the controller to be able to create this file, it needs ids of the files. Therefore I somehow need to be able to send an object containing these ids to the controller, from the client memory. Is this possible to do with forms?

Henrik
  • 11
  • 2
  • 1
    You mean you want to save multiple files on the client with one button? AFAIK a single request can result in a single response=download. This is a protocol limitation. You'll need to open multiple instances. The way this is usually done, is to zip all files into one and download that. edit: See [this answer](https://stackoverflow.com/a/18452049). – JHBonarius Feb 17 '21 at 19:39
  • @JHBonarius I want the possibility to download several documents as one file, that the controller creates based on ids that user has in memory – Henrik Feb 23 '21 at 10:02
  • There are several tutorials online e.g. [this](https://www.c-sharpcorner.com/article/download-multiple-files-in-compressed-format-in-asp-net-mvc-5-step-by-step/) and [this](https://www.aspsnippets.com/Articles/Download-multiple-files-as-Zip-Archive-Compressed-file-in-ASPNet-MVC.aspx). Just google it ;) – JHBonarius Feb 23 '21 at 10:06

0 Answers0