I already have an excel sheet made that will be used as a template for the user to insert data. My question is how can I create a button or link so that upon pressing it, a download will start in the user's browser for the excel template?
Asked
Active
Viewed 157 times
-5
-
Is this a static Excel file? Or will you be generating content in the file? – Sam Axe May 30 '17 at 20:54
-
What do you mean by generating content in the file? In theory, when the file is downloaded, the user will put their data into the excel file – nshull16 May 30 '17 at 20:58
-
It is common to fill in some values when the user clicks the download button. For instance, I have one where I fill in the user's name and email address before they download it. Will you be filling in some values for the user? Or is this a static file - the same for all users? – Sam Axe May 30 '17 at 21:19
-
This file will be the same for all users – nshull16 May 30 '17 at 21:32
-
Possible duplicate of [ASP.NET Excel file download on button click](https://stackoverflow.com/questions/6878525/asp-net-excel-file-download-on-button-click) – Necoras May 30 '17 at 22:16
1 Answers
0
You should have one action in controller which returns your excel sheet and in your cshtml page you can create one button to download it. Below piece of code you cal allow user to download that excel file.
$('#btnYourButtonId').click(function () { window.open('@Url.Action("YourActionName","ControllerName","ExcelName.xls")', "downloadfile"); });
In my case I returned the filepath of my downloadable excel from action of controller.

Nikunj Patel
- 249
- 3
- 13