0
我想返回存儲在我的ASP MVC應用程序的/ images文件夾內的文件(.jpg)。如何在ASP MVC中返回文件?
出於某種原因,下載的文件已損壞/損壞,並且沒有任何照片查看器正在識別該文件。我確定正確的文件是可以訪問的,因爲文件大小完全相同,並且我已經在File()函數中指定了contentType。
請有人可以幫我嗎?謝謝。
public ActionResult order(int? id)
{
// Logic to get the file path and file name from database
// var ImageName = "file"
// var filepath = will be something like ~/images/file.jpg
byte[] filedata = System.IO.File.ReadAllBytes(filepath);
string contentType = MimeMapping.GetMimeMapping(filepath);
return File(filepath, contentType, ImageName+".jpg");
}
看看這個[5826649](http://stackoverflow.com/questions/5826649/returning-a-file-to-view-download-in-asp-net-mvc) –