MVC应用程序.xlsx文件下载作为types文件

我正在处理一个MVC应用程序,并试图链接到我们的用户可以下载的文件共享上的Excel文件。 我以为我把它设置正确,但是当我下载文件它回来作为types“文件”。

UI代码

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

控制器代码

 public FileResult Download() { var FilePath = CurrentSettings.FilePath + "Template Files\\Entry Template.xlsx"; return File(FilePath, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", "Specimen Template File"); } 

这是它在Windows资源pipe理器中的显示方式。

在这里输入图像说明

感觉这是明显的东西,希望别人碰到这个。

您正在使用的File方法的定义是:

 FilePathResult File(string fileName, string contentType, string fileDownloadName) 

如您所见,最后一个参数是文件下载名称。 所以你需要提供文件的名称, 包括扩展名

 return File(FilePath, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", "Specimen Template File.xlsx");