我正在尝试遍历目录并在网页上显示文件。我设法找到了一个脚本,但它没有做循环任何建议?目前我只能查看当前文件夹中的内容
提前谢谢
控制器
public ActionResult Index()
{
DirectoryInfo assetsDirectory = null;
FileInfo[] files = null;
//string salesFTPPath = dirPath;
assetsDirectory = new DirectoryInfo( Server.MapPath("~/assets/img"));
files = assetsDirectory.GetFiles();
Response.Write(assetsDirectory);
var MaterialFiles = (from c in files
select c);
return View(MaterialFiles);
}
看法
@model IEnumerable<FileInfo>
@foreach (var item in Model) {
<tr>
<td>
@item.DirectoryName - @item.Name.ToString()
</td>
</tr>
}