I am getting below error:
The model item passed into the dictionary is of type 'System.Collections.Generic.List
Below is my action method and returning correct result
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);
}
I am not sure my view part is correct or not
@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>
}
below is my 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; }
}
I know error is coming from view html please help me to out this.Thank you in advance for your effort.