I got this error multiple times, and i tried to understand what is exactly wrong but unfortunately i couldn't. So , Any help in this is much appreciated.
Error:
InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'TestApplication.Models.Approval', but this ViewDataDictionary instance requires a model item of type 'System.Collections.Generic.IEnumerable`1[TestApplication.Models.ViewModels.RequestApprovalViewModel]'.
I have 2 models (Requests) & (Approvals). one request could have many approvals.
Here i have the View where i'm displaying all requests where (isDone == true). Next to each request i have button to display a table in a modal popup of this request history.
@modelIEnumerable<TestApplication.Models.ViewModels.RequestApprovalViewModel>@{ViewData["Title"]="Requests";}<table class="table table-bordered table-striped datatable" id="table-3" dir="rtl"><thead><tr><th>Seat number </th><th>RequestDate</th><th>ApprovalStatus</th><th>ApprovalDate</th></tr></thead><tbody>@foreach(var item inModel){<tr><!--Herewhere i should display a table of the approval history of the requst --></tr>}</tbody></table>
You should change one of them to keep their types consistent.
Best Regards,
Jiadong Meng
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
15 Points
33 Posts
this ViewDataDictionary instance requires a model item of type 'System.Collections.Generic.IEnume...
Jul 17, 2020 01:54 PM|ShahadAlshuhail|LINK
I got this error multiple times, and i tried to understand what is exactly wrong but unfortunately i couldn't. So , Any help in this is much appreciated.
Error:
I have 2 models (Requests) & (Approvals). one request could have many approvals.
Here is My Models.
Here i have the View where i'm displaying all requests where (isDone == true). Next to each request i have button to display a table in a modal popup of this request history.
Here is my Controller
My RequestApprovalViewModel
And Finally this is the partialView content
Participant
1320 Points
491 Posts
Re: this ViewDataDictionary instance requires a model item of type 'System.Collections.Generic.IE...
Jul 20, 2020 09:02 AM|jiadongm|LINK
Hi ShahadAlshuhail,
The problem is clear. Here, the item you pass to the partial view is type of Approval , while the partial view accpet a type of
You should change one of them to keep their types consistent.
Best Regards,
Jiadong Meng