Reputation: 21
I have a client and server asp .net app
The client has a form to put some data like name, email phone number. When client press Submit then this data are being sent to the server, and the server returns to controller byte array formatted for xls file. And my question is how to allow the client to download this byte array?
public async Task<> GenerateFile(ExampleModelForm query)
{
byte[] result = await _proxyclient.getfile(query);
}
in 'result' I have this byte[]
array, how return it to the client and allow to download?
Upvotes: 0
Views: 101
Reputation: 247078
The action can be refactored to return that data as a file result so that the browser knows what to do with the response and prompt the user for download
public async Task<IActionResult> GenerateFile(ExampleModelForm query) {
byte[] result = await _proxyclient.getfile(query);
if(result == null)
return NotFound();
return File(result, "application/vnd.ms-excel", "some_filename.xls");
}
Upvotes: 2