我正在使用Razor MVC,我想显示"〜/ Content/uploads"文件夹中的图像.我提出了以下解决方案:
@foreach (FileInfo fileInfo in (new DirectoryInfo(Server.MapPath("~/Content/uploads"))
.GetFiles().Where(x => x.Extension == ".jpg"))) {
<img src="/@fileInfo
.FullName
.Substring(Server.MapPath("~/").Length)
.Replace("\\", "/")"
width="100">
}
Run Code Online (Sandbox Code Playgroud)
代码的问题是我正在获取完整的文件路径,我正在删除Server.MapPath()前缀.
如何简化此代码?