MVC在服务器问题上下载Excel文件

我正在处理一个页面,该页面显示了我们存储在应用程序中的Excel文件的链接。

视图上的链接是这样的:

@Html.ActionLink("Excel sheet", "Download", new { @class = "a" }) 

这反过来又要求:

 public FileResult Download() { return new FilePathResult(Server.MapPath("~Content//SMT Specimen Entry Template.xlsx"), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); } 

但是,当我单击链接时,我得到以下内容:

此网站无法联系到

https://oursite.com/Home/Download?class=a网页可能会暂时closures,或者可能已永久移动到新的url。 觉得这应该很简单,但卡在这里。

我认为你的动作链接是用你的属性作为参数创build的。 为参数添加一个空数组。

 @Html.ActionLink("Excel sheet", "Download", new{ },new { @class = "a" }) 

或者可以

 @Html.ActionLink("Excel sheet", "Download", new { @class = "a" },new{ }) 

其中之一应该工作。