C#MVC5使用ICollcetion显示图像幻灯片

时间:2018-06-06 18:09:07

标签: c# asp.net-mvc icollection

这里我试图在滑块中显示图像。因为foreach循环图像像行一样一个接一个地显示。没有使用foreach我无法获得图像。我不知道如何绑定Icollection并获取照片数据以供查看。 型号:

public partial class PressRelease                            
{                                                                                                                                                                                                                                                                                        
    public PressRelease()             
    {                                                                      
        this.Links = new HashSet<Link>();            
        this.Photos = new HashSet<Photo>();            
    }

    public int pr_id { get; set; }
    public string pr_title { get; set; }
    public string pr_title2 { get; set; }
    public string pr_subtitle { get; set; }

    public virtual ICollection<Link> Links { get; set; }
    public virtual ICollection<Photo> Photos { get; set; }
}

控制器:

public ActionResult Index()                                                           
{
    var pressReleases = _db.pressreleases
                                .Where(p => p.pr_approved)
                                .Include(p => p.Photos)
                                .Include(p => p.Links)
                                .OrderByDescending(p => p.pr_date)
                                .Take(10)
                                .ToList();
    return View(pressReleases);
}

查看:

@model PressRoom.Models.PressRelease

@if (Model.Photos.Count > 0)
{
<div style="padding:10px">

        @foreach (var photos in Model.Photos)
        {            
            <div id="SlideshowImages">
                <img src="@Url.Content(@photos.photo_url)" style="width:100%;height:180px;" />

            </div>
         }
 }

0 个答案:

没有答案