Gewusst wie: downloaden einer Datei, die durch ajax-request in asp.net MVC 4

Unten ist mein code :

ActionResult DownloadAttachment(student st)
{          
    var file = db.EmailAttachmentReceived.FirstOrDefault(x => x.LisaId == st.Lisaid);

    byte[] fileBytes = System.IO.File.ReadAllBytes(file.Filepath);
    return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, file.Filename);                 
}

Dies ist das Skript, welches ich verwende

$(function () {
    $("#DownloadAttachment").click(function () {
        $.ajax({
            url: '@Url.Action("DownloadAttachment", "PostDetail")',
            contentType: 'application/json; charset=utf-8',
            datatype: 'json',
            type: "GET",
            success: function () {
                alert("sucess");
            }
        });    
    });
});      

Wie die Rückkehr der Datei zum download spitzte obigen code?

InformationsquelleAutor rohit singh | 2015-06-08

Schreibe einen Kommentar