Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Can you help me, how to use multiple model in one mvc view?

for example i have two classes called Projects, meetings. i want to show them in one view "Here is my projects...." and "here is my meetings" but i have an error like this;

"The model item passed into the dictionary is of type <system.collections.generic>
but this dictionary requires a model item of type ["Projects"]."

thanks for your help,

have a nice day.
Posted

1 solution

The way the MVC pattern works is: you have a "model" (i.e., data) and you can show it with different "views" (e.g., table, graph...), but a particular view handles only a specific model.

In your case, you may do one of the following:

1) Make "Project" and "Meeting" look the same to the View.

1.1) You can do this by deriving them from the same base class (lets call such base class "Displayable") and prepare your View to show Displayable items or...

1.2) ... by implementing the same interface (lets call such interface "IDisplayable") and prepare your View to handle items implementing the IDisplayable interface.

2) Create different views, one for each model (one for Project lists, and another for Meeting lists).


The error message...

"The model item passed into the dictionary is of type
but this dictionary requires a model item of type ["Projects"]."


... suggests your View only knows "Project" items (or something derived from Projects) and that a "Meeting" is not (meaning, doesn't inherit from) a "Project".
 
Share this answer
 
v2
Comments
Frederico Barbosa 30-Oct-12 7:58am    
Or implement an interface with the methods/properties that your View needs to be able to show items. The point is, a Meeting and a Project must "look" the same to the view, otherwise you need to create a separate view for each type.

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