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