Click here to Skip to main content
15,880,967 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I am getting the following exception.

The model item passed into the dictionary is of type 'Mehra.Models.Customer', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Mehra.Models.Customer]'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'Mehra.Models.Customer', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Mehra.Models.Customer]'.


Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Posted
Updated 30-Jul-15 18:32pm
v4
Comments
Afzaal Ahmad Zeeshan 30-Jul-15 16:54pm    
You need to pass a list of the items, not a single item.

1 solution

The error is generated by the fact that your view is expected to get from the controller a list of items, and you should have in your view something like this:
C#
@model IEnumerable<Mehra.Models.Customer>

But from your controller code you are passing to view an single object of type Customer.

The solution is to pass from controller the expected data, in your case a list of Customer objects.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900