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

Leopoldo Wagner

The whole Error Message:

The model item passed into the dictionary is of type
'MyClass`2[Implementation1,Implementation2]', 
but this dictionary requires a model item of type 
'MyClass`2[Interface1,Interface2]'.

In my View, I have the model declaration:

@model MyClass<Interface1, Interface2>

Where MyClass is a Class and Interface1 and Interface2 are interfaces

on my Controller Action I am calling:

return View(model);

where: model is of type...

MyClass<Implementation1,Implementation2>

...and Implementation1 implements Interface1 and Implementation2 implements Interface2

Is there any way to avoid this error, without having to declare my model as below?

@model MyClass<Implementation1, Implementation2>
Zabavsky

Because MyClass is invariant you can not do this, that means MyClass<Implementation1, Implementation2> is not MyClass<Interface1, Interface2>, hence the error.

As it's not an interface or a delegate, the class cannot to be declared as covariant. Although you can create an interface and make it covariant using out keyword:

public interface IMyClass<out T1, out T2>
{
    ...
}

public class MyClass<T1, T2> : IMyClass<T1, T2>
{
    ...
}

The model declaration in the View:

@model IMyClass<Interface1, Interface2>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

The model item passed into the dictionary is of type .. but this dictionary requires a model item of type

From Dev

The model item passed into the dictionary is of type 'Sitecore.Mvc.Presentation.RenderingModel', but this dictionary requires a model item of type 'X'

From Dev

The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery', but this dictionary requires a model item of type B

From Dev

How to fix The model item passed into the dictionary is of type error?

From Dev

The model item passed into the dictionary is of type 'BlogHomePageModel', but this dictionary requires a model item of type 'BlogHomePageModel'

From Dev

The model item passed into the dictionary is of type 'Umbraco.Web.Models.RenderModel', but this dictionary requires a model item of type 'TestModel'

From Dev

"The model item passed into the dictionary is of type" while passing model to a partial view

From Dev

The model item passed into the dictionary is of type 'System.Net.Http.HttpResponseMessage',

From Dev

The model item passed into the dictionary is of type view model but requires generic IEnum

From Dev

How to handle The model item passed into dictionary is type of LoginViewModel, but this dictionary requires a model type of RegisterViewModel?

From Dev

model item passed into the dictionary is of type 'System.Collections.Generic.List, but this dictionary requires a model item of type

From Dev

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[X]', but this dictionary requires a model item of type 'X'

From Dev

MVC Razor The model item passed into the dictionary is of type List String, but this dictionary requires IEnumerable

From Dev

The model item passed into the dictionary is of type error

From Dev

The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery', but this dictionary requires a model item of type B

From Dev

How to fix The model item passed into the dictionary is of type error?

From Dev

The model item passed into the dictionary is of type 'a', but this dictionary requires a model item of type 'b'

From Dev

The model item passed into the dictionary is of type 'System.Linq.Enumerable

From Dev

The model item passed into the dictionary is of type 'System.Data.Entity.DbSet

From Dev

"The model item passed into the dictionary is of type" while passing model to a partial view

From Dev

This dictionary requires a model item of type 'Umbraco.Web.Models.PartialViewMacroModel'

From Dev

The model passed into dictionary is type 'TestApp.Models.Registration.RegistrationVm' but this dictionary requires a model item of type System.String

From Dev

The model item passed into the dictionary is of type 'System.Int32', but this dictionary requires a model item of type 'IMS.Models.Dealer'

From Dev

The model item passed into the dictionary is of type ' ', but this dictionary requires a model item of type ' '

From Dev

dictionary requires a model item of type 'Projectname.Sp name'

From Dev

ASP.NET MVC 5 The model item passed into the dictionary is of type 'Name.Models.IndexViewModel', but this dictionary requires a model item of type

From Dev

model item passed into the dictionary is of type 'System.Boolean', but this dictionary requires a model item of type 'MyProject.checkboxstate'

From Dev

this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable

From Dev

MVC: The model item passed into the dictionary is of type System.Int32

Related Related

  1. 1

    The model item passed into the dictionary is of type .. but this dictionary requires a model item of type

  2. 2

    The model item passed into the dictionary is of type 'Sitecore.Mvc.Presentation.RenderingModel', but this dictionary requires a model item of type 'X'

  3. 3

    The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery', but this dictionary requires a model item of type B

  4. 4

    How to fix The model item passed into the dictionary is of type error?

  5. 5

    The model item passed into the dictionary is of type 'BlogHomePageModel', but this dictionary requires a model item of type 'BlogHomePageModel'

  6. 6

    The model item passed into the dictionary is of type 'Umbraco.Web.Models.RenderModel', but this dictionary requires a model item of type 'TestModel'

  7. 7

    "The model item passed into the dictionary is of type" while passing model to a partial view

  8. 8

    The model item passed into the dictionary is of type 'System.Net.Http.HttpResponseMessage',

  9. 9

    The model item passed into the dictionary is of type view model but requires generic IEnum

  10. 10

    How to handle The model item passed into dictionary is type of LoginViewModel, but this dictionary requires a model type of RegisterViewModel?

  11. 11

    model item passed into the dictionary is of type 'System.Collections.Generic.List, but this dictionary requires a model item of type

  12. 12

    The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[X]', but this dictionary requires a model item of type 'X'

  13. 13

    MVC Razor The model item passed into the dictionary is of type List String, but this dictionary requires IEnumerable

  14. 14

    The model item passed into the dictionary is of type error

  15. 15

    The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery', but this dictionary requires a model item of type B

  16. 16

    How to fix The model item passed into the dictionary is of type error?

  17. 17

    The model item passed into the dictionary is of type 'a', but this dictionary requires a model item of type 'b'

  18. 18

    The model item passed into the dictionary is of type 'System.Linq.Enumerable

  19. 19

    The model item passed into the dictionary is of type 'System.Data.Entity.DbSet

  20. 20

    "The model item passed into the dictionary is of type" while passing model to a partial view

  21. 21

    This dictionary requires a model item of type 'Umbraco.Web.Models.PartialViewMacroModel'

  22. 22

    The model passed into dictionary is type 'TestApp.Models.Registration.RegistrationVm' but this dictionary requires a model item of type System.String

  23. 23

    The model item passed into the dictionary is of type 'System.Int32', but this dictionary requires a model item of type 'IMS.Models.Dealer'

  24. 24

    The model item passed into the dictionary is of type ' ', but this dictionary requires a model item of type ' '

  25. 25

    dictionary requires a model item of type 'Projectname.Sp name'

  26. 26

    ASP.NET MVC 5 The model item passed into the dictionary is of type 'Name.Models.IndexViewModel', but this dictionary requires a model item of type

  27. 27

    model item passed into the dictionary is of type 'System.Boolean', but this dictionary requires a model item of type 'MyProject.checkboxstate'

  28. 28

    this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable

  29. 29

    MVC: The model item passed into the dictionary is of type System.Int32

HotTag

Archive