下载/打开Excel文件与FileResult MVC4不工作



我试图使用FileResult对象在excel本地磁盘上打开excel文件。当我点击文件打开时,它会下载与我的ActionResult(WTF?)命名相同的文件,当我点击下载的文件时,它会弹出"选择程序"窗口。如果我选择Excel,它会打开它,但我错过了什么,使其下载为Excel文件,并打开它没有额外的步骤?下面是我打开文件的开关语句。由于

public ActionResult GetFile(string path)
    {
        string extension = new FileInfo(path).Extension;
        if (extension != null || extension != string.Empty)
        {
            switch (extension)
            {
                case ".pdf":
                    return File(path, "application/pdf");
                case ".txt":
                    return File(path, "application/plain");
                case ".jpeg":
                    return File(path, "application/jpeg");
                case ".doc":
                    return File(path, "application/msword");
                case ".docx":
                    return File(path, "application/msword");
                case ".xls":
                    return File(path, "application/msexcel");
                case ".xlsx":
                    return File(path, "application/msexcel");
                default:
                    return File(path, "application/octet-stream");
            }
        }
        return View("Index");
    }

检查这个:

 case ".xls":
    return File(path, "application/vnd.ms-excel");
 case ".xlsx":
   return File(path, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
额外信息

相关内容

  • 没有找到相关文章

最新更新