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});





Melvin said:

Thank you, really helpful.

Posted On: February 15, 2020 23:08:30 PM

© 2024 - ErnesTech - Privacy
E-Commerce Return Policy