0

I'm trying to implement file download functionality thru ajax call in MVC. After calling of controller method i always have a "parseerror", can somebody explain me why?

my ajax:

tab.on("click", ".FileDownload", function (e) { //$('#uploadStatus').html("ok"); var tr = $(this).closest("tr"); var id = tr.data("id"); $.ajax({ type: "POST", url: "/File/FileDownload", //contentType: false, //processData: false, //dataType: "json", data: { fileId: id }, success: function (data) { $('#uploadStatus').html("ok"); }, error: function (err) { alert(err.statusText); } }); }); 

and controller:

[HttpPost] public FileResult FileDownload(int? fileId) { FileDBEntities db = new FileDBEntities(); tblFile file = db.tblFiles.ToList().Find(p => p.id == fileId.Value); return File(file.Data, file.ContentType, file.Name); } 

with simple download link in razor it works, but not with ajax. What am I doing wrong here?

1 Answer 1

1

Why not simple use

tab.on("click", ".FileDownload", function (e) { //$('#uploadStatus').html("ok"); var tr = $(this).closest("tr"); var id = tr.data("id"); window.location = window.location.origin + '/File/FileDownload?fileId=' + id; }); [HttpGet] public FileResult FileDownload(int? fileId) 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it was easyer than I've thought XD

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.