c# - 库文件夹封面照片使用 C#

标签 c# css asp.net-mvc-4

我正在使用 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;
}

Controller :

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”的背景。我该怎么做?

最佳答案

我使用 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.

希望对您有所帮助, 谢谢。

关于c# - 库文件夹封面照片使用 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19970495/

相关文章:

c# - Linq to XML 查询返回字符串列表

css - Internet Explorer 10 - CSS3 转换不工作

asp.net-mvc - MVC @html.textbox用于预填充 Guid 默认值

asp.net-mvc-4 - MVC 4 中的一个 View 中是否可以嵌套表单?

c# - 当它们被覆盖时,是否仍然为虚拟自动实现的属性创建匿名支持字段?

c# - 在 VS2010 中放置断点是否会影响程序的运行时行为?

c# - 在 C# 中引发外部对象的事件

jquery - 如何在递归菜单中只选择顶级 li?

css - 中心导航

wcf - 服务引用的正确 url 是什么?