Ajax ファイルダウンロード MVC(vb)

前端之家收集整理的这篇文章主要介绍了Ajax ファイルダウンロード MVC(vb)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

view:

$(function () { $("#DownloadAttachment").click.ajax url: '@Url.Action("DownloadAttachment","PostDetail")', contentType'application/json; charset=utf-8' datatype'json' data studentId 123},54)"> type"GET" success function  windowlocation =;}});});
contoller:
自己修改方法 
Public Function DownFile() As FileStreamResult
      Dim filePath As String = "C:\TEMP\bbb.txt"
      Dim fileName As String = "お願い.txt"
      Dim absoluFilePath As String = filePath 'Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["AttachmentPath"] +   filePath)
      Return File(New System.IO.FileStream(absoluFilePath,System.IO.FileMode.Open),"application/octet-stream",Server.UrlEncode(fileName))
    End Function
网上的方法
public ActionResultDownloadAttachment(int) // Find user by passed id// Student student = db.Students.FirstOrDefault(s => s.Id == studentId); var file  db.EmailAttachmentReceivedFirstOrDefaultx => xLisaId==);byte[] fileBytes SystemIOFileReadAllBytesfileFilepathreturnfileBytesNetMimeMediaTypeNamesApplicationOctet fileFilename}
http://stackoverflow.com/questions/30704078/how-to-download-a-file-through-ajax-request-in-asp-net-mvc-4 原文链接:https://www.f2er.com/ajax/161927.html

猜你在找的Ajax相关文章