我正在使用C#在ASP.NET MVC 4中完成我的项目。我的网站上有一个画廊页面。要列出gallery文件夹中的每个相册文件夹,我使用以下代码
型号:
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”的背景。我怎么能这样做?
答案 0 :(得分: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.
希望这有帮助, 感谢。