I am trying to create a partial view to display a list of items but keep running into this error which
The model item passed into the dictionary is of type 'Revision.Models.GroupEvent', but this dictionary requires a model item of type 'System.Collections.Generic.GroupIEnumerable`1[Revision.Models.Event]'.'
This is my Home Controller
public class HomeController : Controller
{
public RevisionDb db = new RevisionDb();
EventViewModels evm = new EventViewModels();
public ActionResult Index()
{
evm.Events = db.GroupEvents.ToList();
return View(new GroupEvent() { EventPartialModel = evm.Events.ToList()} );
}
}
This is the View Model I am using
public class EventViewModels
{
public int NumberofEvents { get; set; }
public List<GroupEvent> Events { get; set; }
public int EventCount { get; set; }
}
This is my Partial View
@model IEnumerable<Revision.Models.GroupEvent>
@using Revision.Models
@if (Model != null)
{
<div class="grid">
<table cellspacing="0" width="80%">
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>Date</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td align="left">@item.EventTitle</td>
<td align="left">@item.EventDesc</td>
<td align="left">@item.EventDate</td>
</tr>
}
</tbody>
</table>
</div>
}
And this is my main view
@model IEnumerable<Revision.Models.GroupEvent>
@{
ViewBag.Title = "Index";
}
<a href="~/Models/GroupEvents.cs">~/Models/GroupEvents.cs</a>
<div>
@Html.Partial("EventsPartialView", Model)
</div>