Asp.Net Core Error: InvalidOperationException: The model item passed into the ViewDataDictionary is of type '<>f__AnonymousType7`2[System.Int32,System.String]', but this ViewDataDictionary instance requires a model item of type 'Modal'.



Problem: InvalidOperationException: The model item passed into the ViewDataDictionary is of type '<>f__AnonymousType7`2[System.Int32,System.String]', but this ViewDataDictionary instance requires a model item of type 'Modal'.

Solution: If you have worked on this problem and suddenly have not found a solution, it is possible that you copied a View from another Controller's View Folder. Visual Studio tracks meta data for Views, Controllers and Models (among other things). 
  - If you copied the View from another folder, rename the View that is giving you problems and generate a new View from scratch.

   - After a new View has been Scaffolded (generated) copy your source code from the View that gave you problems (remember not to copy every code, try migrating code in blocks, as this will give you visibility to what code is causing the error.)

- Pay attention to the code inside the function you are posting the form data to, make sure that the function is returning to a correct View, for example,  if you entended the function to return RedirectToAction("ActionName", new {paramName = value, paramName2 = value2}) that it is not defined as return View("ActionName", new {param1 = value});

asp.net Core 3.1 asp.net mvc asp.net core errors asp.net web forms asp.net core tutorial Technology published
Was this page helpful?
Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback

Other users would like to know if this solution helped you.

Melvin said:

Thank you, really helpful.

Your Session is Ending
Login to Continue


© 2021 - ErnesTech - Privacy