0

I am calling the MVC controller which returns a FileResult back using XMLHttpRequest. For some reason i don't get a prompt for download/save the file , i do get the file content as the response from the get request(Checked in network tab).

I don't have the url of the file only have contentbytes, so can't use window.location

Please help.

2 Answers 2

1

Do not use XMLHttpRequest to open file link, do

Sign up to request clarification or add additional context in comments.

2 Comments

I don't have the url, i only havecontent bytes
Without url, you can not call XMLHttpRequest. Put screenshot of your network tab
0

Before returning the file in your controller action, try to add a content-disposition header (directly as below, or using System.Net.Mime.ContentDisposition).

Response.AppendHeader("content-disposition", "inline; filename=" + fileName);

Also have a look at RFC 6266

On the client side, call the url that returns the attachment:

window.open('..../controller-name/action-that-returns-the-file');

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.