2013-11-14 3 views
0

Я делаю свой проект в ASP.NET MVC 4 с использованием C#. У меня есть страница галереи на моем сайте. Для перечисления каждого альбома папки в папку галереи я использую следующий код,Галерея Папки Обложка фото с использованием C#

Модель:

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/[email protected]"> <div class="galframe"><div class="galframepic"></div><div class="galframecaption"><p>@item</p></div></div></a> 
} 

Я хочу установить обложки или каждую из папок альбома, используя изображения внутри этой конкретной папки (например, Faceboo k альбомов). Фактически, одно из изображений из этой конкретной папки отображается как фон div «galframepic». Как я могу это сделать?

ответ

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. 

Надеюсь, что это поможет, Спасибо.

Смежные вопросы