Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用mvc显示要查看的本地文件夹中的图像_C#_Model View Controller - Fatal编程技术网

C# 如何使用mvc显示要查看的本地文件夹中的图像

C# 如何使用mvc显示要查看的本地文件夹中的图像,c#,model-view-controller,C#,Model View Controller,我正在使用MVC。我需要上传图像,并显示在同一页它。 我已上载图像并将图像存储在本地文件夹中。 如何使用mvc显示本地文件夹文件中的图像最好的方法是创建一个操作,从文件夹加载文件并返回它 使用FileContentResult: public FileContentResult Display(string filename) { byte[] byteArray = GetImageFromDisk(filename); return new FileContentResult(b

我正在使用MVC。我需要上传图像,并显示在同一页它。 我已上载图像并将图像存储在本地文件夹中。
如何使用mvc显示本地文件夹文件中的图像最好的方法是创建一个操作,从文件夹加载文件并返回它

使用
FileContentResult

public FileContentResult Display(string filename) {
   byte[] byteArray = GetImageFromDisk(filename);
   return new FileContentResult(byteArray, "image/jpeg");
}

以上是一个非常简单的示例,您可以在这里找到答案: