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?