Friday, June 12, 2009

User download a file ASP.NET MVC with AJAX

I wanted the user to be able to download a file, using ASP.NET MVC with AJAX. The problem wasn't downloading, or AJAX. It was the two together.

It's really simple. What you need to do is get the path of the file to download, put the value in ViewData and make an href to that file with value "Download" to target="_blank". This will show a popup to download the file.

[lt]a href='[lt]%=path%[gt]' target="_blank" [gt] Download [lt]/a[gt]

[lt] = "<"
[gt] = ">"

No comments:

Post a Comment