【发布时间】:2011-06-29 04:44:46
【问题描述】:
我要做的是在我的 MVC 应用程序的视图中显示位于我的服务器上的文件夹的内容。
我有我认为应该为 Action 准备的内容,但是我有点不确定如何实施相应的视图,我想知道是否有人可以指出正确的方向。 (而且,如果有人认为我的 Action 可以改进,欢迎提出建议 :))
下面是动作:
public ActionResult Index()
{
DirectoryInfo salesFTPDirectory = null;
FileInfo[] files = null;
try
{
string salesFTPPath = "E:/ftproot/sales";
salesFTPDirectory = new DirectoryInfo(salesFTPPath);
files = salesFTPDirectory.GetFiles();
}
catch (DirectoryNotFoundException exp)
{
throw new FTPSalesFileProcessingException("Could not open the ftp directory", exp);
}
catch (IOException exp)
{
throw new FTPSalesFileProcessingException("Failed to access directory", exp);
}
files = files.OrderBy(f => f.Name).ToArray();
var salesFiles = files.Where(f => f.Extension == ".xls" || f.Extension == ".xml");
return View(salesFiles);
}
任何帮助将不胜感激,谢谢:)
【问题讨论】:
-
您只想将它们显示为列表吗?如果是这样,标准的索引视图就不会太远了。在 MVC 3 中创建视图时,您可以选择一个模板作为其基础。
标签: c# asp.net-mvc view .net