I want to display a partial view in Main View, Based on this ViewModel.
The Main view use all models in ViewModel, but partial view use the first model.
public class EventManagementViewModel
{
public IEnumerable<BPMSPARS.Models.DomainModels.CalendarEvent> Eventslist { get; set; }
public BPMSPARS.Models.DomainModels.CalendarEvent Event { get; set; }
public BPMSPARS.Models.DomainModels.EventsUser EventUser { get; set; }
}
in controller I have this code:
[HttpGet]
public ActionResult Event()//partial view
{
EventManagementViewModel VM = new EventManagementViewModel();
return PartialView(VM.Eventslist);
}
public ActionResult EventCalendar()//main view
{
EventManagementViewModel VM = new EventManagementViewModel();
return View(VM);
}
in mainview i have this code:
@model BPMSPARS.ViewModels.EventManagementViewModel
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
//..
<div>
@Html.Partial("Event",Model.Eventslist)
</div>
in partial view i have this code:
@model IEnumerable<BPMSPARS.Models.DomainModels.CalendarEvent>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.EventName)
</th>
<th>
@Html.DisplayNameFor(model => model.EventColor)
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.EventName)
</td>
<td>
@Html.DisplayFor(modelItem => item.EventColor)
</td>
</tr>
}
</table>
But when I run the main view i face this error:
Message "The model item passed into the dictionary is of type 'BPMSPARS.ViewModels.EventManagementViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[BPMSPARS.Models.DomainModels.CalendarEvent]'." string
Do you know What should I do? I think I must change the definition of models,on the other hand I don't how another definition is possible? I search this topic But i don't find the exact problem that I faced it.