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'

digiShadoe

*CORRECTION

The problem occurs when my view is called to populate a list from my user table.

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

Here is my controller action:

    public ActionResult Registration(Mike.Models.User user)
    {
        if (ModelState.IsValid)
        {
            using (var db = new UserContext())
            {

                var crypto = new SimpleCrypto.PBKDF2();
                var encrypPass = crypto.Compute(user.password);
                var sysUser = db.Users.Create();

                sysUser.LastName = user.LastName;
                sysUser.FirstName = user.FirstName;
                sysUser.Email = user.Email;
                sysUser.password = encrypPass;
                sysUser.passwordSalt = crypto.Salt;
                sysUser.UserID = user.UserID;
                db.Users.Add(sysUser);
                db.SaveChanges();

                return RedirectToAction("Index", "Home");
            }


        }

        return View(user);
    }

Can someone please help me.... There are responses to similar questions on the internet but I believe mine is unique.. I have searched for weeks to no avail.

Thanks in advance,

Renior

Here is my simple controller action...

   public ActionResult Index()
    {

        return View(db.Users.ToList());

    }

and my razor syntax.

@model IEnumerable

Im trying to populate a view of my user table list..

Marko

In your Registration view at the top where your model declaration is, instead of this:

@model List<Mike.Models.User>

you need to have:

@model Mike.Models.User

You probably used strongly typed scaffolding feature to generate your view but instead of details option you chose a list option...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

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

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

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 ..., but this dictionary requires ...

From Dev

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

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 ' ', but this dictionary requires a model item of type ' '

From Dev

Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Collections.Generic.List`

From Dev

The model item passed into the dictionary is of type 'System.Threading.Tasks.Task`1[System.Collections.Generic.IEnumerable`

From Dev

MVC: Dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1

From Dev

MVC: Dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1

From Dev

The model item passed into the dictionary is of type 'System.Collections.Generic.List... in ASP.net MVC

From Dev

ASP.Net MVC "The model item passed into the dictionary is of type 'System.Collections.Generic.List"

From Dev

The model item passed into the dictionary is of type 'System.Collections.Generic.List in Razor mvc5

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

'System.Collections.Generic.List`1[<>f__AnonymousType1 but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable 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

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

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 '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 'BlogHomePageModel', but this dictionary requires a model item of type 'BlogHomePageModel'

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 passed into dictionary is type 'TestApp.Models.Registration.RegistrationVm' but this dictionary requires a model item of type System.String

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

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 'System.Net.Http.HttpResponseMessage',

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

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

Related Related

  1. 1

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

  2. 2

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

  3. 3

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

  4. 4

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

  5. 5

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

  6. 6

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

  7. 7

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

  8. 8

    Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Collections.Generic.List`

  9. 9

    The model item passed into the dictionary is of type 'System.Threading.Tasks.Task`1[System.Collections.Generic.IEnumerable`

  10. 10

    MVC: Dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1

  11. 11

    MVC: Dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1

  12. 12

    The model item passed into the dictionary is of type 'System.Collections.Generic.List... in ASP.net MVC

  13. 13

    ASP.Net MVC "The model item passed into the dictionary is of type 'System.Collections.Generic.List"

  14. 14

    The model item passed into the dictionary is of type 'System.Collections.Generic.List in Razor mvc5

  15. 15

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

  16. 16

    'System.Collections.Generic.List`1[<>f__AnonymousType1 but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable ERROR

  17. 17

    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

  18. 18

    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

  19. 19

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

  20. 20

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

  21. 21

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

  22. 22

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

  23. 23

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

  24. 24

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

  25. 25

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

  26. 26

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

  27. 27

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

  28. 28

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

  29. 29

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

HotTag

Archive