1

こんにちは、c# を使用して mvc4 のプロジェクトを行っています。ディレクトリ内のすべてのサブディレクトリを取得しようとしています。ビューにリストします

そのために私は次のコードを書いています

コントローラ

public ActionResult Gallery()
    {
        string folderpath = Server.MapPath("~/Content/Gallery/GalleryImages");
        List<string> currentimage = new Gallery().GetGalleryName(folderpath);
        //What will be the return type???/
        return View(currentimage);
    }

モデル

public List<string> GetGalleryName(string path)
    {
        DirectoryInfo di = new DirectoryInfo(path);
        DirectoryInfo[] subdir = di.GetDirectories();
        List<String> files = new List<String>();
        foreach (DirectoryInfo dir in subdir)
        {
            var name = dir.Name;
            files.Add(name);
        }

        return files;
    }

私のコードは正しいですか?では、コントローラーとモデルの戻り値の型はどうなるでしょうか? 私を助けてください

4

3 に答える 3

0

コントローラーでこれを試してください

public ActionResult Gallery()
{
  List<String> galleryList = new List<String>();
  string folderpath = Server.MapPath("~/Content/Gallery/GalleryImages");
  string[] currentimage = new Gallery().GetGalleryName(folderpath);
  foreach (var folder in currentimage) {
    galleryList.Add(folder);
  }
return View(galleryList);
}
于 2013-10-04T04:51:20.127 に答える