I have a form in one of my razor-pages which when submitted, will generate a byte[]
and the I return a FileStreamResult
. The problem is, all that happens is the page refreshes and I'm not prompted to download a file.
Here's my form:
<form autocomplete="off" method="post" asp-page-handler="attendance" asp-route-id="@Model.Data.Id">
<div class="form-group">
<label class="font-weight-bold">Date of meeting</label>
<input class="form-control datepicker" id="meeting-date" type="text" value="DateOfMeeting" />
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block">Download document</button>
</div>
</form>
And this is my page handler:
public async Task<IActionResult> OnPostAttendanceAsync(int id)
{
var query = new AttendanceList.Query {
Date = DateOfMeeting,
SchoolId = id
};
var model = await _mediator.Send(query);
var stream = new MemoryStream(model.Data);
return new FileStreamResult(stream, ContentType.Pdf) {
FileDownloadName = "Attendance.pdf"
};
}
I don't understand what I'm missing here.
Edit: The handler is being called successfully. If I put a breakpoint in and debug, the handler completes successfully, but no file sent to the browser.
FileResult
with thebyte[]
directly. – Chris Pratt