开发者

How in ASP.NET MVC 2 with no JS/AJAX make delay download page

开发者 https://www.devze.com 2023-04-04 11:51 出处:网络
I want to make download page after but开发者_如何学Cton click. This page should show some information and then, after some time start downloading file. the best if that would work withouns JavaScript

I want to make download page after but开发者_如何学Cton click. This page should show some information and then, after some time start downloading file. the best if that would work withouns JavaScript and Ajax. I ave tried with async controller but this not really works like I want.


I can only think of one way to make this happen. Add an HTTP header (refresh) that redirects the browser to the download link after the interval. Since the link will return a response that's an attachment, it shouldn't actually refresh the browser page, but it should begin the download. In the head section of your view add:

<meta http-equiv="refresh" content="30; ,URL=@Model.DownloadURL">

This assumes that your model contains the URL for the download in the DownloadURL model property. It should begin the download after 30 seconds.

As an aside, AJAX might help to get the initial download page shown, but you can't download files via AJAX. That takes a full request since the XMLHttpRequest doesn't handle Content-Disposition: attachment.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号