0

我正在使用 C# 在 ASP.NET MVC 4 中做我的项目。我的网站上有一个画廊页面。为了列出画廊文件夹中的每个专辑文件夹,我使用以下代码,

模型:

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)
    {
        files.Add(dir.Name);
    }
    return files;
}

控制器:

public ActionResult Gallery()
{
    string folderpath = Server.MapPath("~/Images/Gallery");
    List<String> currentimage = new Gallery().GetGalleryName(folderpath);
    return View(currentimage);
}

cshtml:

@foreach(var item in Model)
{
<a href="~/Home/Show?foldername=@item"> <div class="galframe"><div class="galframepic"></div><div class="galframecaption"><p>@item</p></div></div></a>
}

我想通过使用特定文件夹中的图像(如 Facebook 相册)来设置封面或每个相册文件夹。实际上,该特定文件夹中的一张图像显示为 div“galframepic”的背景。我该怎么做?

4

1 回答 1

1

我使用 asp.net webform 来完成几乎相同类型的任务。我正在分享我的工作流程,看看它是否对您有所帮助。

1. Create an entry form for album. In this form there will be two input fields
  a) Album name field of type text
  b) file type input field.
  c) when album name is given and an image file is uploaded to a certain directory then save  the directoryPath+imageFileName in your database along with the Album name.

2) In another page fetch the previously save data for the album from database. And use image that was uploaded in the directory as the cover folder of the album. you can also show the album name that is fetched along with the (directoryPath+imageFileName) below the image.

希望这会有所帮助,谢谢。

于 2013-11-14T06:26:35.607 回答