IFL IFL - 8 months ago 44
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


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');