我收到以下错误:
传递给字典的模型项的类型为“System.Collections.Generic.List
下面是我的操作方法并返回正确的结果
public ActionResult Gellery()
{
var list = db.EventGallerys.GroupBy(eg => new
{
EventId = eg.EventId,
Title = eg.Title,
EventDate = eg.EventDate,
Description = eg.Description,
ThumbImage = eg.ThumbImage
})
.OrderByDescending(eg => eg.Key.EventDate)
.Take(5)
.AsEnumerable()
.Select(eg => new
{
EventId = eg.Key.EventId,
Day = eg.Key.EventDate.ToString("D"),
Month = eg.Key.EventDate.ToString("MMM"),
Year = eg.Key.EventDate.ToString("yyyy"),
Title = eg.Key.Title,
Description = eg.Key.Description,
ThumbImage = eg.Key.ThumbImage
}).ToList();
// var list = db.EventGallerys.ToList();
return View(list);
}
我不确定我的观点部分是否正确
@model List<IBAC.Models.EventGalleryViewModel>
@{ ViewBag.Title = "Gellery"; }
<h2>Gellery</h2>
@foreach (var item in Model)
{
<a href='@Url.Content("~/GalleryImages/" + item.ThumbImage)'>
<img class='thumbnail' src='@Url.Content("~/GalleryImages/" + item.ThumbImage)' />
</a>
}
下面是我的 Viewmodelclass
public class EventGalleryViewModel
{
public string EventId { get; set; }
public string Day { get; set; }
public string Month { get; set; }
public string Year { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string ThumbImage { get; set; }
}
我知道错误来自视图 html,请帮助我解决这个问题。提前感谢您的努力。
至尊宝的传说
相关分类