C# 如何使用mvc显示要查看的本地文件夹中的图像
我正在使用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显示本地文件夹文件中的图像最好的方法是创建一个操作,从文件夹加载文件并返回它 使用
FileContentResult
:
public FileContentResult Display(string filename) {
byte[] byteArray = GetImageFromDisk(filename);
return new FileContentResult(byteArray, "image/jpeg");
}
以上是一个非常简单的示例,您可以在这里找到答案: