c# - The model item passed into the dictionary is of type ..., but this dictionary requires ... -


Whole error message:

  The model item type given in the dictionary 'Miklaus 2 [implementation 1, implementation 2] ', but this dictionary requires a model item called' Myklos '2 [Interface 1, Interface 2]'.   

In my view, I have a model declaration:

  @modelmiclas & lt; Interface 1, Interface 2 & gt;   

Where my class is a class and interface 1 and the interface 2 interface

I'm calling on my controller action:

 < Code> return view (ideal);   

Where: Model is of type ...

  MyClass & lt; Implementation 1, Implementation 2 & gt; Applies  Interface 1  and  Implementation 2    

... and Implementation 1 < strong> Interface 2 @modelmiclus & lt; Implementation 1, Implementation 2 & gt; Is there any way to avoid this error?

Because MyClass is unchanging You can not do this, which means MyClass & lt; Implementation 1, Implementation 2 & gt; is not MyClass & lt; Interface 1, Interface 2 & gt; , hence the error.

As this is not an interface or a representative, the class can not be declared as covariant , although you can create an interface and use it Are covariant:

  Public Interface IMyClass & lt; Out T1, outside T2 & gt; {...} Public Classroom MyLux & lt; T1, T2 & gt; : IMIClass & lt; T1, T2 & gt; {...}   

Model announcement in view:

  @EmyClass model    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -