IFL IFL - 1 year ago 101
Ajax Question

Download a file with mvc

I need to allow the user on my site to download a file (xml File)

I tried

public FileResult DownloadFile(string fileid)
if (!string.IsNullOrEmpty(fileid))
byte[] fileBytes = Encoding.ASCII.GetBytes(FileData);
return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet,FileName + ".bccx");
return null;


function downloadFile(id) {
url: sitePath + "Controller/DownloadFile?fileid=" + id,
type: 'post',
asysnc: false
.done(function () {


but nothing is downloaded

Answer Source

Does it have to be done using ajax? Maybe you could open another window with the file generation address and let the browser do the job:

function downloadFile(id) {

    window.open(sitePath + "Controller/DownloadFile?fileid=" + id, '_blank');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download