0

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?

1 Answer 1

2

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");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.