Ajax ¥Õ¥¡¥¤¥ë¥À¥¦¥ó¥í©`¥É MVC(vb)
·¢²¼Ê±¼ä£º2020-12-16 01:30:49 ËùÊôÀ¸Ä¿£º°Ù¿Æ À´Ô´£ºÍøÂçÕûÀí
µ¼¶Á£º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
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:TEMPbbb.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 £¨±à¼£ºÀî´óͬ£© ¡¾ÉùÃ÷¡¿±¾Õ¾ÄÚÈݾùÀ´×ÔÍøÂ磬ÆäÏà¹ØÑÔÂÛ½ö´ú±í×÷Õ߸öÈ˹۵㣬²»´ú±í±¾Õ¾Á¢³¡¡£ÈôÎÞÒâÇÖ·¸µ½ÄúµÄȨÀû£¬Ç뼰ʱÓëÁªÏµÕ¾³¤É¾³ýÏà¹ØÄÚÈÝ! |
Ïà¹ØÄÚÈÝ
- ÕýÔò±í´ïʽ30·ÖÖÓÈëÃŽ̳Ì
- ruby-on-rails ¨C Õë¶Ô²»Í¬Óû§½ÇÉ«µÄ²»Í¬ÊÓͼ¼¯
- c ¨C ÕâЩ±»ÈÏΪÊÇħÊõÊý×ÖÂð£¿
- Ôõô֪µÀÊÇiphone»¹ÊÇipad£¿
- ruby-on-rails ¨C rails 4.0ÖеĶà¸ö¡°root to¡±Â·ÓÉ
- ʹÓÃrubyÖеÄ×Ô¶¯´´½¨ÍÆÈëÊý×é
- c# ¨C ÈçºÎÔÚÒ»¸öÏîÄ¿Öд´½¨²»Í¬µÄDLL£¿
- c# ¨C ÈçºÎ»ñµÃpictureboxµÄ·Ç¹«¿ª³ÉÔ±µÄ¼ÛÖµ£¿
- ÓëAjaxµÄ³õ´ÎıÃæ
- ÈçºÎʹÓÃWPF´ÓXMLÎļþ´´½¨treeview£¿
ÍƼöÎÄÕÂ
Õ¾³¤ÍƼö
ÈȵãÔĶÁ